use core::iter;
use core::num::{self, NonZero};
use crate::patterns::{impl_newtype_generic, impl_via_array};
use crate::Exhaust;
macro_rules! impl_nonzero {
($t:ty) => {
impl Exhaust for NonZero<$t> {
type Iter = ExhaustNonZero<$t, NonZero<$t>>;
fn exhaust_factories() -> Self::Iter {
ExhaustNonZero::<$t, NonZero<$t>>(
<$t>::exhaust_factories().filter_map(NonZero::new),
)
}
crate::patterns::factory_is_self!();
}
};
}
impl_nonzero!(i8);
impl_nonzero!(i16);
impl_nonzero!(i32);
impl_nonzero!(u8);
impl_nonzero!(u16);
impl_nonzero!(u32);
#[derive(Clone, Debug)]
#[doc(hidden)]
#[allow(clippy::type_complexity)]
pub struct ExhaustNonZero<T: Exhaust, N>(
iter::FilterMap<<T as Exhaust>::Iter, fn(<T as Exhaust>::Factory) -> Option<N>>,
);
impl<T: Exhaust, N> Iterator for ExhaustNonZero<T, N> {
type Item = N;
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}
impl<T: Exhaust, N> iter::FusedIterator for ExhaustNonZero<T, N> {}
impl_via_array!(
num::FpCategory,
[
Self::Nan,
Self::Infinite,
Self::Zero,
Self::Subnormal,
Self::Normal,
]
);
impl_newtype_generic!(T: [], num::Wrapping<T>, num::Wrapping);