toto 1.1.0

This crate provides a simple conversion method between basic numerical types
Documentation
//! Trait for converting various numeric types to usize
//! 
//! This module defines the [ToUsize] trait which provides a method for converting
//! different numeric types to usize. It includes implementations for all primitive
//! numeric types including unsigned integers, signed integers and floating point numbers.

/// A trait for converting a value to usize
///
/// This trait provides a standardized way to convert various numeric types to usize.
/// It is automatically implemented for all primitive numeric types.
///
/// # Examples
///
/// ```
/// use toto::traits::tousize::ToUsize;
///
/// let x: u8 = 42;
/// let y: usize = x.to_usize();
/// assert_eq!(y, 42_usize);
///
/// let z: i32 = -100;
/// let w: usize = z.to_usize();
/// assert_eq!(w, 18446744073709551516_usize); // -100 casted to usize (on 64-bit platform)
/// ```
pub trait ToUsize {
    /// Converts the given value to usize
    ///
    /// This method performs a type cast from the implementing type to usize,
    /// using Rust's `as` operator semantics.
    ///
    /// # Returns
    ///
    /// The usize representation of the value
    fn to_usize(self) -> usize;
}

/// Implementation of ToUsize for u8
///
/// Converts a u8 value to usize using the `as` operator.
impl ToUsize for u8 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for u16
///
/// Converts a u16 value to usize using the `as` operator.
impl ToUsize for u16 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for u64
///
/// Converts a u64 value to usize using the `as` operator.
impl ToUsize for u64 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for u128
///
/// Converts a u128 value to usize using the `as` operator.
impl ToUsize for u128 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for i8
///
/// Converts an i8 value to usize using the `as` operator.
impl ToUsize for i8 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for i16
///
/// Converts an i16 value to usize using the `as` operator.
impl ToUsize for i16 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for i32
///
/// Converts an i32 value to usize using the `as` operator.
impl ToUsize for i32 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for i64
///
/// Converts an i64 value to usize using the `as` operator.
impl ToUsize for i64 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for i128
///
/// Converts an i128 value to usize using the `as` operator.
impl ToUsize for i128 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for f32
///
/// Converts an f32 value to usize using the `as` operator.
/// Note that this may involve precision loss due to the difference in
/// representation between floating point and integer types.
impl ToUsize for f32 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}

/// Implementation of ToUsize for f64
///
/// Converts an f64 value to usize using the `as` operator.
/// Note that this may involve precision loss due to the difference in
/// representation between floating point and integer types.
impl ToUsize for f64 {
    #[inline]
    fn to_usize(self) -> usize {
        self as usize
    }
}