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

后端 未结 1 1139
悲&欢浪女
悲&欢浪女 2020-12-02 01:55

I tried to derive serde::Deserialize for a struct containing a reference to a Path. This yielded an error message which doesn\'t occur if you repla

相关标签:
1条回答
  • 2020-12-02 02:44

    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

    0 讨论(0)
提交回复
热议问题