I have this simple generic function:
fn add_five<T: Into<i32>>(t: T) -> i32 {
5_i32 + t.into()
}
Which I would like to express using the From trait instead of the Into trait, however my attempted refactor:
fn add_five<T, i32: From<T>>(t: T) -> i32 {
5_i32 + <i32 as From<T>>::from(t)
}
Throws this compile error:
error[E0277]: cannot add `i32` to `i32`
--> src/main.rs:24:11
|
| 5_i32 + <i32 as From<T>>::from(t)
| ^ no implementation for `i32 + i32`
|
= help: the trait `Add<i32>` is not implemented for `i32`
Which is very confusing, because there is indeed an impl Add<i32> for i32 in the standard library, so what's the real problem?