Why can Serde not derive Deserialize for a struct containing only a &Path?

Add an attribute to the field: #[serde(borrow)]. That will indicate to serde that it should be borrowing the value. You must provide this attribute for every borrow except for &str and &[u8].

Source: https://serde.rs/lifetimes.html#borrowing-data-in-a-derived-impl

Leave a Comment