I'm trying to add serialization functionality to one of my structs in Rust.
It's an event for a calendar and looks like this:
#[derive(PartialEq, Clone, Encodable, Decodable)]
pub struct Event {
pub id: Uuid,
pub name: String,
pub desc: String,
pub location: String,
pub start: DateTime<Local>,
pub end: DateTime<Local>,
}
The struct uses two different types from third-parties, the Uuid
is from https://github.com/rust-lang/uuid and the DateTime
from https://github.com/lifthrasiir/rust-chrono.
If I try to build the project the compiler complains that encode
was not found for Uuid
and DateTime
, which is because they both do not derive Encodable
and Decodeable
, from the serialize
crate.
So the questions are:
Is there a way to add derives to third-party structs without touching the code of the libs itself? If not, what is the best way to add serialization functionality in a situation like this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…