/*
 * SPDX-License-Identifier: MIT
 * Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
 */

use crate::{FromPrimitive, ToPrimitive};

impl FromPrimitive for isize {
    #[inline]
    fn from_isize(n: isize) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_i8(n: i8) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_i16(n: i16) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_i32(n: i32) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_i64(n: i64) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_i128(n: i128) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_usize(n: usize) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_u8(n: u8) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_u16(n: u16) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_u32(n: u32) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_u64(n: u64) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_u128(n: u128) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_f32(n: f32) -> Option<isize> {
        n.to_isize()
    }
    #[inline]
    fn from_f64(n: f64) -> Option<isize> {
        n.to_isize()
    }
}

impl FromPrimitive for i8 {
    #[inline]
    fn from_isize(n: isize) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_i8(n: i8) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_i16(n: i16) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_i32(n: i32) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_i64(n: i64) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_i128(n: i128) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_usize(n: usize) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_u8(n: u8) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_u16(n: u16) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_u32(n: u32) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_u64(n: u64) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_u128(n: u128) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_f32(n: f32) -> Option<i8> {
        n.to_i8()
    }
    #[inline]
    fn from_f64(n: f64) -> Option<i8> {
        n.to_i8()
    }
}

impl FromPrimitive for i16 {
    #[inline]
    fn from_isize(n: isize) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_i8(n: i8) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_i16(n: i16) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_i32(n: i32) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_i64(n: i64) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_i128(n: i128) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_usize(n: usize) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_u8(n: u8) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_u16(n: u16) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_u32(n: u32) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_u64(n: u64) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_u128(n: u128) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_f32(n: f32) -> Option<i16> {
        n.to_i16()
    }
    #[inline]
    fn from_f64(n: f64) -> Option<i16> {
        n.to_i16()
    }
}

impl FromPrimitive for i32 {
    #[inline]
    fn from_isize(n: isize) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_i8(n: i8) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_i16(n: i16) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_i32(n: i32) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_i64(n: i64) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_i128(n: i128) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_usize(n: usize) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_u8(n: u8) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_u16(n: u16) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_u32(n: u32) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_u64(n: u64) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_u128(n: u128) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_f32(n: f32) -> Option<i32> {
        n.to_i32()
    }
    #[inline]
    fn from_f64(n: f64) -> Option<i32> {
        n.to_i32()
    }
}

impl FromPrimitive for i64 {
    #[inline]
    fn from_isize(n: isize) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_i8(n: i8) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_i16(n: i16) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_i32(n: i32) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_i64(n: i64) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_i128(n: i128) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_usize(n: usize) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_u8(n: u8) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_u16(n: u16) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_u32(n: u32) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_u64(n: u64) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_u128(n: u128) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_f32(n: f32) -> Option<i64> {
        n.to_i64()
    }
    #[inline]
    fn from_f64(n: f64) -> Option<i64> {
        n.to_i64()
    }
}

impl FromPrimitive for i128 {
    #[inline]
    fn from_isize(n: isize) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_i8(n: i8) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_i16(n: i16) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_i32(n: i32) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_i64(n: i64) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_i128(n: i128) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_usize(n: usize) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_u8(n: u8) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_u16(n: u16) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_u32(n: u32) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_u64(n: u64) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_u128(n: u128) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_f32(n: f32) -> Option<i128> {
        n.to_i128()
    }
    #[inline]
    fn from_f64(n: f64) -> Option<i128> {
        n.to_i128()
    }
}
