ts-rust-helper 0.11.0

Various helper functions, structures, and traits for working on my Rust projects.
Documentation
//! Common functions for integers.
//!

/// Common functions for integers.
pub trait Integer<const BYTES: usize> {
    /// Creates a native endian integer value from its representation as a byte array in big endian.
    fn from_be_bytes(bytes: [u8; BYTES]) -> Self;
    /// Creates a native endian integer value from its representation as a byte array in little endian.
    fn from_le_bytes(bytes: [u8; BYTES]) -> Self;
    /// Creates a native endian integer value from its representation as a byte array in native endian.
    fn from_ne_bytes(bytes: [u8; BYTES]) -> Self;
}

impl Integer<1> for u8 {
    fn from_be_bytes(bytes: [u8; 1]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 1]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 1]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<2> for u16 {
    fn from_be_bytes(bytes: [u8; 2]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 2]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 2]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<4> for u32 {
    fn from_be_bytes(bytes: [u8; 4]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 4]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 4]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<8> for u64 {
    fn from_be_bytes(bytes: [u8; 8]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 8]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 8]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<16> for u128 {
    fn from_be_bytes(bytes: [u8; 16]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 16]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 16]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<1> for i8 {
    fn from_be_bytes(bytes: [u8; 1]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 1]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 1]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<2> for i16 {
    fn from_be_bytes(bytes: [u8; 2]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 2]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 2]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<4> for i32 {
    fn from_be_bytes(bytes: [u8; 4]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 4]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 4]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<8> for i64 {
    fn from_be_bytes(bytes: [u8; 8]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 8]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 8]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}
impl Integer<16> for i128 {
    fn from_be_bytes(bytes: [u8; 16]) -> Self {
        Self::from_be_bytes(bytes)
    }

    fn from_le_bytes(bytes: [u8; 16]) -> Self {
        Self::from_le_bytes(bytes)
    }

    fn from_ne_bytes(bytes: [u8; 16]) -> Self {
        Self::from_ne_bytes(bytes)
    }
}