You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, received an error, and I assume the default for chrono::Duration should be Duration::zero(), anyway I tried to wrap Duration into my struct and implement Default trait for that and have no luck.
Thanks
use serde::{Deserialize,Serialize};use chrono::Duration;#[derive(Debug,Serialize,Deserialize)]structMyStruct{#[serde(skip)]duration:Duration,f:i32,}fnmain(){// Create an instance of MyStructlet my_struct = MyStruct{duration:Duration::minutes(30),f:12,};// Serialize it to JSONlet serialized = serde_json::to_string(&my_struct).unwrap();println!("Serialized: {}", serialized);// Deserialize from JSONlet deserialized:MyStruct = serde_json::from_str(&serialized).unwrap();println!("Deserialized: {:?}", deserialized);}
The error:
error[E0277]: the trait bound `chrono::Duration: Default` is not satisfied
--> src/main.rs:6:5
|
6 | #[serde(skip)]
| ^ the trait `Default` is not implemented for `chrono::Duration`
The text was updated successfully, but these errors were encountered:
@akaNightmare For a long time we could not implement Default, because chrono::Duration was (depending on a feature flag) a re-export of time 0.1 time::Duration. A bit more than a week ago we made a release to change this, see https://github.com/chronotope/chrono/releases/tag/v0.4.30. This was a tricky release, but we haven't gotten negative feedback yet.
Hopefully soon #1137 can be merged that adds features to chrono::Duration such as this.
Hello, received an error, and I assume the default for chrono::Duration should be
Duration::zero()
, anyway I tried to wrap Duration into my struct and implement Default trait for that and have no luck.Thanks
The error:
The text was updated successfully, but these errors were encountered: