Lifetime error of serde’s impl-deserializer example


I am learning serde and reading its document of implementing a custom deserializer. All goes well, until I added a definition of a wrapper struct in the test_struct function.
See line 735 in the code.

Then rustc complained about the lifetime comflicting in the process of deriving Deserialize for struct Wrapper<‘a>( Test<‘a> ).

Why and how?


You need to indicate that you’re borrowing the data for that field from the input:

struct Wrapper<'a>(#[serde(borrow)] Test<'a> ); has more info.


Thanks! I did glanced over that chapter before you mentioned, but didn’t realized it was the answer to my question.