Help: associated type in trait that implements a trait with a lifetime parameter


#1

The associated type should implement the serde::Deserialize trait and own all its data, but I’m getting lifetime errors that make no sense to me when trying to convert a json string into an Output in a function.

pub trait Private<'a> {
    type Output: serde::Deserialize<'a>;
}

https://play.rust-lang.org/?gist=59c1a7e54f46a5a9689bfd2bd86f73ed&version=stable


#2

I think you want the following:

pub trait Private {
    // the output type does not need to borrow anything
    type Output: for<'a> serde::Deserialize<'a>;
}

And this is basically https://docs.serde.rs/serde/de/trait.DeserializeOwned.html :slight_smile:


#3

Thanks, the DeserializeOwned trait is what I needed here.