use {
core::{
fmt::{self, Display, Formatter},
num::{
NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
},
},
super::super::Int,
};
macro_rules! impl_from_unsigned_for_int { ($($ty: ty),+$(,)?) => {
$(
impl From<$ty> for Int {
fn from(n: $ty) -> Self {
Self::U64(n.into())
}
}
)+
impl From<usize> for Int {
fn from(n: usize) -> Self {
Self::Usize(n)
}
}
impl From<NonZeroUsize> for Int {
fn from(n: NonZeroUsize) -> Self {
Self::Usize(n.get())
}
}
}}
impl_from_unsigned_for_int!(u8, u16, u32, u64);
macro_rules! impl_from_signed_for_int { ($($ty: ty),+$(,)?) => {
$(
impl From<$ty> for Int {
fn from(n: $ty) -> Self {
Self::I64(n.into())
}
}
)+
impl From<isize> for Int {
fn from(n: isize) -> Self {
Self::Isize(n)
}
}
impl From<NonZeroIsize> for Int {
fn from(n: NonZeroIsize) -> Self {
Self::Isize(n.get())
}
}
}}
impl_from_signed_for_int!(i8, i16, i32, i64);
macro_rules! impl_from_non_zero_unsigned_for_int { ($($ty: ty),+$(,)?) => {
$(
impl From<$ty> for Int {
fn from(n: $ty) -> Self {
Self::U64(n.get().into())
}
}
)+
}}
impl_from_non_zero_unsigned_for_int!(NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64);
macro_rules! impl_from_non_zero_signed_for_int { ($($ty: ty),+$(,)?) => {
$(
impl From<$ty> for Int {
fn from(n: $ty) -> Self {
Self::I64(n.get().into())
}
}
)+
}}
impl_from_non_zero_signed_for_int!(NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64);
impl Display for Int {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.write_str(&self.fmt())
}
}