[solved] Need help with lifetimes for serde::Deserialize

#1

Hello, today I had a rough fight with lifetimes. I lost :expressionless:

I have many JSON files/schemas to parse and I want to parse them using only one generic function using the following syntax
parse::<LangSchema>(); parse::<UserSchema>();

Here is the code to the playground with comments Link. I hope they will describe the problem correctly.

Do you have any advice for me? Or rather how many advices do you have :slight_smile:
Thanks a lot for any help!

#2

Have you already seen https://serde.rs/lifetimes.html ?

1 Like
#3

Hi, yeah.
I did read it once again today and I found out that I need to deserialize from owned value. Thanks for suggestion!: )

working example

Then compiler suggested to me a following syntax for where statement:

where
    for<'a> T: serde::Deserialize<'a>

And Iโ€™m like. What? Thatโ€™s exactly what I wanted to type - the lifetime for the for clause.
Time to read more about trait bound (I guess thatโ€™s how itโ€™s called).
Explanation in Nomicon