StructA implements From<StructB>, and StructB implements From<S>.
How can I generically implement a 'shortcut' Into<StructA> for S or From<S> for StructA?
If this is a bad idea, please do tell. But kindly explain how to do it anyway for the sake of learning.
Here's my attempt:
struct StructA {
f: StructB
}
struct StructB {
g: i32
}
impl From<StructB> for StructA {
fn from(v: StructB) -> Self {
Self {
f: v
}
}
}
impl From<i32> for StructB {
fn from(v: i32) -> Self {
Self {
g: v
}
}
}
impl<T: Into<StructA>, S: Into<T>> Into<StructA> for S {
fn into(self) -> StructA {
let i: T = self.into();
i.into()
}
}
The error I get is the type parameter 'T' is not constrained by the impl trait, self type, or predicates.
I don't understand it. Isn't T constrained by Into<StructA>?