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

KiB

Copyright (C) 2016-2017, 2019-2020, 2022, 2024-2025  Anonymous

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

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/>.

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

use {
    core::{
        fmt::{self, Display, Formatter},
        num::{
            NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
        },
    },
    super::super::Int,
};

// ╔════════════════╗
// ║   Primitives   ║
// ╚════════════════╝

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);

// ╔═════════════╗
// ║   Display   ║
// ╚═════════════╝

impl Display for Int {

    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        f.write_str(&self.fmt())
    }

}