Sometimes we wish to generalise an implementation of a trait over many integer types, and applying them one by one becomes too cumbersome. In the vein of generalising integers, I propose the Int, SignedInt and UnsignedInt traits.
pub trait Int {
// Associated consts
pub const MIN: Self;
pub const MAX: Self;
pub const BITS: u32;
// Associated functions and methods
pub const fn leading_zeros(self) -> u32 {}
// ...
}
pub trait SignedInt: Int {
pub fn is_negative(self) -> bool;
pub fn is_positive(self) -> bool;
// ...
}
pub trait UnsignedInt: Int {
// ...
}
impl Int for u8 {
// ...
}
impl Int for i8 {
// ...
}
impl UnsignedInt for u8 {
// ...
}
impl SignedInt for i8 {
// ...
}