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§