num_conv

Trait CastUnsigned

Source
pub trait CastUnsigned: Integer {
    type Unsigned;

    // Required method
    fn cast_unsigned(self) -> Self::Unsigned;
}
Expand description

Cast to an unsigned integer of the same size.

This trait is implemented for all integers. Signed to unsigned casts are equivalent to 0.wrapping_add_unsigned(value), while unsigned to unsigned casts are an identity conversion.

assert_eq!((-1_i8).cast_unsigned(), u8::MAX);
assert_eq!((-1_i16).cast_unsigned(), u16::MAX);
assert_eq!((-1_i32).cast_unsigned(), u32::MAX);
assert_eq!((-1_i64).cast_unsigned(), u64::MAX);
assert_eq!((-1_i128).cast_unsigned(), u128::MAX);
assert_eq!((-1_isize).cast_unsigned(), usize::MAX);
assert_eq!(0_u8.cast_unsigned(), 0_u8);
assert_eq!(0_u16.cast_unsigned(), 0_u16);
assert_eq!(0_u32.cast_unsigned(), 0_u32);
assert_eq!(0_u64.cast_unsigned(), 0_u64);
assert_eq!(0_u128.cast_unsigned(), 0_u128);
assert_eq!(0_usize.cast_unsigned(), 0_usize);

Required Associated Types§

Source

type Unsigned

The unsigned integer type with the same size as Self.

Required Methods§

Source

fn cast_unsigned(self) -> Self::Unsigned

Cast an integer to the unsigned integer of the same size.

Implementations on Foreign Types§

Source§

impl CastUnsigned for i8

Source§

impl CastUnsigned for i16

Source§

impl CastUnsigned for i32

Source§

impl CastUnsigned for i64

Source§

impl CastUnsigned for i128

Source§

impl CastUnsigned for isize

Source§

impl CastUnsigned for u8

Source§

impl CastUnsigned for u16

Source§

impl CastUnsigned for u32

Source§

impl CastUnsigned for u64

Source§

impl CastUnsigned for u128

Source§

impl CastUnsigned for usize

Implementors§