我试图利用DateTime从rust chrono crate 到我自己的特点.

#[derive(Debug, RustcEncodable, RustcDecodable)]
pub struct Accomplishment {
  name: String,
  accomplishment_type: String,
  date: DateTime<UTC>
}

当我试图编译它时,它抱怨说

src/lib.rs:11:33: 11:47 error: the trait `rustc_serialize::serialize::Decodable` is not implemented for the type `chrono::datetime::DateTime<chrono::offset::utc::UTC>` [E0277]
src/lib.rs:11 #[derive(Debug, RustcEncodable, RustcDecodable)]

当我判断github repo of chrono时,它实现了rustc_序列化支持.但这是一个特点.在commit log年,它做到了

cargo test -v --features rustc-serialize

我不确定如何在我的项目中使用此功能.有人能帮我把chrono和rustc serialize一起使用吗?

关于这一点,有similar question分.但我想要的是在我的项目中使用chrono中提供的序列化支持,而不实现包装器特性.

推荐答案

将该功能添加到Cargo.toml中的依赖项中

[dependencies.chrono]
version = "*"
features = ["rustc-serialize"]

The relevant Documentation can be found here

Rust相关问答推荐

关联类型(类型参数)命名约定

Arrow RecordBatch as Polars DataFrame

如何从铁 rust 中呼唤_mm_256_mul_ph?

如何使用 list 在Rust for Windows中编译?

如果成员都实现特征,是否在多态集合上实现部分重叠的特征?

在析构赋值中使用一些现有绑定

带参考文献的 rust 元组解构

Pin<;&;mut可能将Uninit<;T>;>;合并为Pin<;&;mut T>;

创建Rust中元对象协议的动态对象 Select /重新分配机制

在macro_rule中拆分模块和函数名

解析程序无法在Cargo 发布中 Select 依赖版本

习语选项<;T>;到选项<;U>;当T->;U用From定义

为什么BufReader实际上没有缓冲短寻道?

Rust Axum 框架 - 解包安全吗?

将 &str 或 String 保存在变量中

分配给下划线模式时会发生什么?

为什么可以在迭代器引用上调用 into_iter?

有没有办法阻止 rust-analyzer 使非活动代码变暗?

Rust - 在线程之间不安全地共享没有互斥量的可变数据

制作嵌套迭代器的迭代器