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

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!

Have you already seen Deserializer lifetimes ยท Serde ?

1 Like

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

1 Like