-
Notifications
You must be signed in to change notification settings - Fork 592
Closed as not planned
Description
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)]
struct MyStruct {
#[serde(skip)]
duration: Duration,
f: i32,
}
fn main() {
// Create an instance of MyStruct
let my_struct = MyStruct {
duration: Duration::minutes(30),
f: 12,
};
// Serialize it to JSON
let serialized = serde_json::to_string(&my_struct).unwrap();
println!("Serialized: {}", serialized);
// Deserialize from JSON
let 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`
Metadata
Metadata
Assignees
Labels
No labels