This issue is best described with this playground.
struct Foo;
impl From<&[u8]> for Foo {
fn from(_: &[u8]) -> Foo {
Foo
}
}
What's in main()
is proven to work, but I don't know how I can express that within the generic function without triggering compiler error E0637.
fn main() {
let v = vec![0u8]; // <-- works!
Foo::from(v.as_slice());
}
fn trigger_lifetime_issue_but_not_e637<'a, T>()
where
T: From<&'a[u8]> {
let v = vec![0u8];
T::from(v.as_slice()); // <-- Doesn't work because 'a is enforced by E0637
}
When trying to learn more about E0637 in search for a solution/alternative, I have to read between the lines.
This issue occours in a real work program, and I work around this with unnecessary owned values.
How can I use T: From<&[u8]>
in a trait bound without triggering lifetime issues while avoiding E0637?