Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json Serialization feature of chrono crate

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)]

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

I'm not sure how to have this feature for my project. Can someone help me on how to use chrono with rustc-serialize?

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.

like image 610
Chathurika Sandarenu Avatar asked Jul 09 '15 08:07

Chathurika Sandarenu


1 Answers

Add the feature to your dependency in the Cargo.toml

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

The relevant Documentation can be found here

like image 192
oli_obk Avatar answered Oct 15 '22 06:10

oli_obk