chrono crate 的 Json 序列化功能 [英] Json Serialization feature of chrono crate
问题描述
我正在尝试将 rust-chrono 板条箱中的 DateTime 用于我自己的特征.
I'm trying to use DateTime from rust-chrono crate to my own trait.
#[derive(Debug, RustcEncodable, RustcDecodable)]
pub struct Accomplishment {
name: String,
accomplishment_type: String,
date: DateTime<UTC>
}
当我尝试编译它时它抱怨
When I try to compile this it complains that
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_serialize 支持.但它是一个功能.在 提交日志中有
When I checked the github repo of chrono it had the rustc_serialize support implemented. But it is as a feature. In commit log it has
cargo test -v --features rustc-serialize
我不确定如何为我的项目提供此功能.有人可以帮助我如何在 rustc-serialize 中使用 chrono 吗?
I'm not sure how to have this feature for my project. Can someone help me on how to use chrono with rustc-serialize?
有一个关于此的类似问题.但我想要的是在我的项目中使用 chrono 中可用的序列化支持,而无需实现包装器特征.
There is a similar question regarding this. But what I wanted is to use the serialization support available in chrono in my project without implementing a wrapper trait.
推荐答案
在 Cargo.toml
[dependencies.chrono]
version = "*"
features = ["rustc-serialize"]
相关文档可以在这里找到
这篇关于chrono crate 的 Json 序列化功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!