Open geeknoid opened 5 months ago
It's possible to add, and you can emulate this now with T::min_value() < T::zero()
, which is probably how we would write a default implementation in the trait.
Since the to_*
methods return Option
, you could also write it based on the runtime values like this:
if let Some(i) = v.to_i64() {
// signed operations using `i`
} else {
let u = v.to_u64().expect("unsigned number");
}
When working in a generic context, it would be useful to access whether a PrimInt-based generic type is signed or not signed at build time.