Use the trait NumberAs
in the current scope to let all primitive number types have a number_as
method.
```rust use number_as::NumberAs;
let a: i32 = 2u16.number_as();
assert_eq!(2i32, a);
asserteq!(2i32, 2u16.numberas());
asserteq!(20i32, 20.6.numberas()); ```
All implements for the NumberAs
trait can be considered as a whole Primitive Number. If you want to design an add function, which accepts all kinds of primitive numbers,
you can use the Number
trait as a trait bound.
```rust use number_as::{Number, NumberAs};
fn add
let c = a + b;
c.number_as()
}
assert_eq!(40i32, add(5u8, 35i16)); ```
https://crates.io/crates/number-as
https://docs.rs/number-as