pub trait Key {
fn from_u8(key: &[u8]) -> Self;
fn as_slice<T, F: Fn(&[u8]) -> T>(&self, f: F) -> T;
}
pub fn from_u8<K: Key>(key: &[u8]) -> K {
Key::from_u8(key)
}
struct MyKey<'a>(&'a [u8]);
impl Key for MyKey<'_> {
fn from_u8(key: &[u8]) -> Self {
MyKey(key)
}
fn as_slice<T, F: Fn(&[u8]) -> T>(&self, f: F) -> T {
f(&self.0)
}
}
How can I impl from_u8
for MyStruct
, the compiler tells that "cannot infer an appropriate lifetime for lifetime parameter 'a
due to conflicting requirements".