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§
Required Methods§
Sourcefn cast_unsigned(self) -> Self::Unsigned
fn cast_unsigned(self) -> Self::Unsigned
Cast an integer to the unsigned integer of the same size.