I have some code, but the problem boilds down to this:
pub struct Thing<S>
where S: AsRef<str> // im using AsRef here but the point is just that `S` is string-like
{
this: S
}
impl<S> Default for Thing<S>
where S: AsRef<str> {
fn default() -> Self {
Self {
this: "i am a `&'static str`"
}
}
}
Cargo says:
expected type parameter `S`
found reference `&'static str`
I get that the problem is something to do with it being a reference to an str
, I just don't really know what to do about it. How do I restrict a generic to being "string like", while making sure that said generic can be at least an &str
or a String
?