extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
use chrono::{self, Date,DateTime, TimeZone};
use serde_derive::{Serialize,Deserialize}; // 1.0.91
#[derive(Serialize,Deserialize )]
struct Test<Tz>
where Tz:TimeZone,
{
t:DateTime<Tz>
}
fn main(){
}
The code above is not gonna compile with the error:
error[E0277]: the trait bound
chrono::datetime::DateTime<Tz>: serde::Serialize
is not satisfied --> src/main.rs:16:5
I have
chrono = {version="0.4",features = ["serde"]}
in my Cargo.toml
I found that the implementation is here: https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#impl-Serialize
full code sample here https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=57b41f6dd1c4c0a2c7f4f541234137a7
but I am not sure if the playground have serde feature enabled or not.
Sorry guys the problems is as @crazysim said in the comment.
DateTime didn't implement Deserialize trait.
If I remove it, the code will work:
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
use chrono::{self,DateTime, TimeZone};
#[derive(Serialize )]
struct Test<Tz>
where Tz:TimeZone,
{
t:DateTime<Tz>
}
fn main(){
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With