Documentation
/*
==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--

SJ

Copyright (C) 2019-2025  Anonymous

There are several releases over multiple years,
they are listed as ranges, such as: "2019-2025".

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--
*/

//! # `NonZero*`

use {
    core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8},
    crate::{Error, Number, Result},
};

#[cfg(any(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))]
use core::num::{NonZeroIsize, NonZeroUsize};

macro_rules! impl_from_non_zeros_for_number { ($($ty: ty),+$(,)?) => {
    $(
        impl From<&$ty> for Number {

            fn from(n: &$ty) -> Self {
                Self::from(n.get())
            }

        }

        impl From<$ty> for Number {

            fn from(n: $ty) -> Self {
                Self::from(n.get())
            }

        }
    )+
}}

impl_from_non_zeros_for_number!(
    NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128,
    NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128,
);

#[cfg(any(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))]
impl_from_non_zeros_for_number!(NonZeroUsize, NonZeroIsize);

macro_rules! impl_try_from_number_for_non_zeros { ($(($non_zero: ty, $ty: ty)),+$(,)?) => {
    $(
        impl TryFrom<&Number> for $non_zero {

            type Error = Error;

            fn try_from(n: &Number) -> Result<Self> {
                Self::try_from(<$ty>::try_from(n)?).map_err(|e| err!("{e}"))
            }

        }

        impl TryFrom<Number> for $non_zero {

            type Error = Error;

            fn try_from(n: Number) -> Result<Self> {
                Self::try_from(&n)
            }

        }
    )+
}}

impl_try_from_number_for_non_zeros!(
    (NonZeroI8, i8), (NonZeroI16, i16), (NonZeroI32, i32), (NonZeroI64, i64), (NonZeroI128, i128), (NonZeroIsize, isize),
    (NonZeroU8, u8), (NonZeroU16, u16), (NonZeroU32, u32), (NonZeroU64, u64), (NonZeroU128, u128), (NonZeroUsize, usize),
);