macro_rules! from_integer {
(int for: $for:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( from_integer![@int for: $for + $for_b, from: $from + $from_b]; )+
};
(@int for: $for:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for+$for_b, from: @$from+$from_b, arg:f, body: {
Self(f.0.into())
});
};
(int_non0 for: $for:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( from_integer![@int_non0 for: $for + $for_b, from: $from + $from_b]; )+
};
(@int_non0 for: $for:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for+$for_b, from: @$from+$from_b, arg:f, body: {
Self::new(f.0.into()).unwrap()
});
};
(non0 for: $for:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( from_integer![@non0 for: $for + $for_b, from: $from + $from_b]; )+
};
(@non0 for: $for:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for+$for_b, from: @$from+$from_b, arg:f, body: {
#[cfg(feature = "safe")]
return Self::from_innermost_repr(f.0.get().into()).unwrap();
#[cfg(not(feature = "safe"))]
return unsafe { Self::from_innermost_repr_unchecked(f.0.get().into()) };
});
};
(neg_signed
for: $for:ident + $p:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( from_integer![@neg_signed for: $for + $p + $for_b, from: $from + $from_b]; )+
};
(@neg_signed
for: $for:ident + $p:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
devela::paste! {
$crate::all::impl_from!(for: $for+$for_b, from: @$from+$from_b, arg:f, body: {
Self(Into::<[<$p$for_b>]>::into(f.0).neg())
});
}
};
(negnon0_signed
for: $for:ident + $p:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( from_integer![@negnon0_signed for: $for + $p + $for_b, from: $from + $from_b]; )+
};
(@negnon0_signed
for: $for:ident + $p:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
devela::paste! {
$crate::all::impl_from!(for: $for+$for_b, from: @$from+$from_b, arg:f, body: {
#[cfg(feature = "safe")]
return Self::from_innermost_repr(Into::<[<$p$for_b>]>::into(f.0.get()).neg()).unwrap();
#[cfg(not(feature = "safe"))]
return unsafe {
Self::from_innermost_repr_unchecked(Into::<[<$p$for_b>]>::into(f.0.get()).neg())
};
});
}
};
}
pub(crate) use from_integer;
macro_rules! from_primitive {
(int for: $for:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( from_primitive![@int for: $for + $for_b, from: $from + $from_b]; )+
};
(@int for: $for:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for+$for_b, from: $from+$from_b, arg:f, body: {
#[cfg(feature = "safe")]
return Self::from_inner_repr(f.into()).unwrap();
#[cfg(not(feature = "safe"))]
return unsafe { Self::from_inner_repr_unchecked(f.into()) };
});
$crate::all::impl_from!(for: $for+$for_b, from: &$from+$from_b, arg:f, body: {
#[cfg(feature = "safe")]
return Self::from_inner_repr((*f).into()).unwrap();
#[cfg(not(feature = "safe"))]
return unsafe { Self::from_inner_repr_unchecked((*f).into()) };
});
};
(non0 for: $for:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( from_primitive![@non0 for: $for + $for_b, from: $from + $from_b]; )+
};
(@non0 for: $for:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for+$for_b, from: $from+$from_b, arg:f, body: {
#[cfg(feature = "safe")]
return Self::from_innermost_repr(f.get().into()).unwrap();
#[cfg(not(feature = "safe"))]
return unsafe { Self::from_innermost_repr_unchecked(f.get().into()) };
});
$crate::all::impl_from!(for: $for+$for_b, from: &$from+$from_b, arg:f, body: {
#[cfg(feature = "safe")]
return Self::from_innermost_repr((*f).get().into()).unwrap();
#[cfg(not(feature = "safe"))]
return unsafe { Self::from_innermost_repr_unchecked((*f).get().into()) };
});
};
}
pub(crate) use from_primitive;
macro_rules! for_primitive {
(int for: $for:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( for_primitive![@int for: $for + $for_b, from: $from + $from_b]; )+
};
(@int for: $for:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for+$for_b, from: @$from+$from_b, arg:f, body: {
f.0.into()
});
};
(non0 for: $for:ident + $for_b:expr, from: $from:ident + $( $from_b:expr ),+) => {
$( for_primitive![@non0 for: $for + $for_b, from: $from + $from_b]; )+
};
(@non0 for: $for:ident + $for_b:expr, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for+$for_b, from: @$from+$from_b, arg:f, body: {
f.0.get().into()
});
};
}
pub(crate) use for_primitive;
#[cfg(feature = "dashu-int")]
macro_rules! for_big {
(int for: $for:ident, from: $from:ident + $( $from_b:expr ),+) => {
$( for_big![@int for: $for, from: $from + $from_b]; )+
};
(@int for: $for:ident, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for, from: @$from+$from_b, arg:f, body: {
Self(f.0.into())
});
};
(intneg for: $for:ident, from: $from:ident + $( $from_b:expr ),+) => {
$( for_big![@intneg for: $for, from: $from + $from_b]; )+
};
(@intneg for: $for:ident, from: $from:ident + $from_b:expr) => {
devela::paste! {
$crate::all::impl_from!(for: $for, from: @$from+$from_b, arg:f, body: {
Self(<dashu_int::IBig>::from(f.0).neg())
});
}
};
(non0int for: $for:ident, from: $from:ident + $( $from_b:expr ),+) => {
$( for_big![@non0int for: $for, from: $from + $from_b]; )+
};
(@non0int for: $for:ident, from: $from:ident + $from_b:expr) => {
$crate::all::impl_from!(for: $for, from: @$from+$from_b, arg:f, body: {
Self(f.0.get().into())
});
};
(non0intneg for: $for:ident, from: $from:ident + $( $from_b:expr ),+) => {
$( for_big![@non0intneg for: $for, from: $from + $from_b]; )+
};
(@non0intneg for: $for:ident, from: $from:ident + $from_b:expr) => {
devela::paste! {
$crate::all::impl_from!(for: $for, from: @$from+$from_b, arg:f, body: {
Self(<dashu_int::IBig>::from(f.0.get()).neg())
});
}
};
(prim for: $for:ident, from: $from:ident + $( $from_b:expr ),+) => {
$( for_big![@prim for: $for, from: $from + $from_b]; )+
};
(@prim for: $for:ident, from: $from:ident + $from_b:expr) => {
devela::paste! {
$crate::all::impl_from!(for: $for, from: $from+$from_b, arg:f, body: {
Self(f.into())
});
$crate::all::impl_from!(for: $for, from: &$from+$from_b, arg:f, body: {
Self(<dashu_int::IBig>::from(*f))
});
}
};
(non0prim for: $for:ident, from: $from:ident + $( $from_b:expr ),+) => {
$( for_big![@non0prim for: $for, from: $from + $from_b]; )+
};
(@non0prim for: $for:ident, from: $from:ident + $from_b:expr) => {
devela::paste! {
use core::num::[<$from$from_b>];
$crate::all::impl_from!(for: $for, from: $from+$from_b, arg:f, body: {
Self(f.get().into())
});
$crate::all::impl_from!(for: $for, from: &$from+$from_b, arg:f, body: {
Self(<dashu_int::IBig>::from(f.get()))
});
}
};
}
#[cfg(feature = "dashu-int")]
pub(crate) use for_big;