If I have something like
use serde_json;
use iso8601::DateTime;
#[derive(Deserialize, Debug)]
pub struct Thing {
pub attr: i32,
pub foo: i32,
pub ts: DateTime
}
The compiler is also going to insist that I ensure DateTime
satisfies the trait bound Deserialize
:
error: the trait bound `iso8601::DateTime: serde::Deserialize` is not satisfied [E0277]
src/lib.rs:208 #[derive(Deserialize, Debug)
You can't place the derive annotation above the included struct, or the compiler will complain. In fact, the plot thickens, as DateTime
itself has structs that would need the same annotation:
pub struct DateTime {
pub date: Date,
pub time: Time,
}
Is there a way to swing this, or do I have to implement these traits manually for external structs?
Edit: Let me be clear, I was asking about the #[derive]
macro. I read the linked and related questions, and I understand that I can provide my own implementation of different traits, as well as use newtypes etc. That is not what I am asking about.
Cargo.toml
serde = "0.8"
serde_json = "0.8"
serde_macros = "0.8"
iso8601 = "0.1.1"