use std::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
use super::PrimUnsignedInt;
pub trait NonZero: Copy + Sized {
type Int: PrimUnsignedInt<NonZero = Self>;
unsafe fn new_unchecked(n: Self::Int) -> Self;
fn new(n: Self::Int) -> Option<Self>;
fn get(self) -> Self::Int;
}
macro_rules! nonzero_traits {
( $( $Ty: ident($Int: ty); )+ ) => {
$(
impl NonZero for $Ty {
type Int = $Int;
unsafe fn new_unchecked(n: Self::Int) -> Self {
Self::new_unchecked(n)
}
#[allow(clippy::new_ret_no_self)]
fn new(n: Self::Int) -> Option<Self> {
Self::new(n)
}
fn get(self) -> Self::Int {
self.get()
}
}
)+
};
}
nonzero_traits! {
NonZeroU8(u8);
NonZeroU16(u16);
NonZeroU32(u32);
NonZeroU64(u64);
NonZeroU128(u128);
NonZeroUsize(usize);
}