Or without cast
the trait std::convert::From<T> is not implemented for element::Element
Here is my Element
The problem shows too if I tried to implement NumCast and ToPrimitive but always is the same error the trait num_traits::cast::NumCastis not implemented forT``. I will be glad to some help.
You can cast T to any integer (NumCast) and you can go from a specific integer, (i32 it seems) to an Element. In such cases, Rust is currently unable to "guess the hole" when two generic functions are chained, even if there is only one type to fill the "hole" (i32).
So you need to be explicit about the transformation "path" and tell Rust to use i32 as the intermediary step. So, instead of:
other option is to bind T by T : ToPrimitive and call value.to_i32().unwrap(). This way the code is more readable and more versatile (NumCast is a subtrait of ToPrimitive).
@Yandros Thank you. What should I add when I want to add casting from f32? Some match with few number types and inside cast to current type? Of course I need to change specification of generic type.