Question
Define lifetime for associative type without lifetime bound
I am implementing FromStr
for a type and for the error I want to return the passed &str
inside a wrapper struct. However, this requires the the struct to have a lifetime bound for the &str
but that will cause errors inside FromStr
since its associative type Err
does not have any lifetime bounds and cannot be modified either. Lastly, it's not possible to add a lifetime bound to the impl
since the lifetime does not get constrained by anything, at least in the ways I have tried. So, how can I squeeze in my wrapper into the associative type?
For more context, here are the definitions:
pub enum RarityTag {
// ...
}
pub struct ParseRarityTagError<'a>(&'a str);
impl FromStr for RarityTag {
type Err = ParseRarityTagError<'a>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
// ...
rest => Err(ParseRarityTagError(rest)),
}
}
}