The error message basically states that the compiler has no way to infer what type T
may be – it basically has to figure out whether any type T
exists such that the given trait bounds T: Into<StructA>, S: Into<T>
are satisfied, and this is not possible in Rust. One problem with this is, as stated in the comments, that there might be multiple types T
satisfying the trait bounds, in which case the compiler can't determine which one to use.
In addition, the Into
trait already has a blanket implementation in the standard library.
impl<T, U: From<T>> Into<U> for T;
There is no way for the compiler to guarantee that this impl doesn't overlap with your blanket impl, which would also make the implementation ambiguous.
I recommend you simply implement From<i32> for StructA
explicitly. If you need many such implementations, macros could be useful.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…