use crate::{PrimitiveInteger, PrimitiveIntegerRef, PrimitiveSigned};
pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
type Signed: PrimitiveSigned;
fn abs_diff(self, other: Self) -> Self;
fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self>;
fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
fn checked_next_power_of_two(self) -> Option<Self>;
fn div_ceil(self, rhs: Self) -> Self;
fn is_power_of_two(self) -> bool;
fn midpoint(self, other: Self) -> Self;
fn next_multiple_of(self, rhs: Self) -> Self;
fn next_power_of_two(self) -> Self;
fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool);
fn saturating_add_signed(self, rhs: Self::Signed) -> Self;
fn wrapping_add_signed(self, rhs: Self::Signed) -> Self;
}
pub trait PrimitiveUnsignedRef<T>: PrimitiveIntegerRef<T> {}
macro_rules! impl_unsigned {
($Unsigned:ident, $Signed:ty) => {
impl PrimitiveUnsigned for $Unsigned {
type Signed = $Signed;
forward! {
fn abs_diff(self, other: Self) -> Self;
fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self>;
fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
fn checked_next_power_of_two(self) -> Option<Self>;
fn div_ceil(self, rhs: Self) -> Self;
fn is_power_of_two(self) -> bool;
fn midpoint(self, other: Self) -> Self;
fn next_multiple_of(self, rhs: Self) -> Self;
fn next_power_of_two(self) -> Self;
fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool);
fn saturating_add_signed(self, rhs: Self::Signed) -> Self;
fn wrapping_add_signed(self, rhs: Self::Signed) -> Self;
}
}
impl PrimitiveUnsignedRef<$Unsigned> for &$Unsigned {}
};
}
impl_unsigned!(u8, i8);
impl_unsigned!(u16, i16);
impl_unsigned!(u32, i32);
impl_unsigned!(u64, i64);
impl_unsigned!(u128, i128);
impl_unsigned!(usize, isize);