Skip to main content

CastUnsigned

Trait CastUnsigned 

Source
pub trait CastUnsigned: Sized {
    type Unsigned;

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

Reinterprets a signed integer’s bits as its unsigned counterpart.

For value-checked conversion to the unsigned counterpart, use CheckedCast / SaturatingCast / StrictCast with the unsigned target type.

Required Associated Types§

Source

type Unsigned

The unsigned counterpart type (e.g. u32 for i32).

Required Methods§

Source

fn cast_unsigned(self) -> Self::Unsigned

Returns the bit pattern of self reinterpreted as its unsigned counterpart (two’s complement: negative values become large).

use const_num_traits::CastUnsigned;

assert_eq!(CastUnsigned::cast_unsigned(-1i8), 255u8);
assert_eq!(CastUnsigned::cast_unsigned(127i8), 127u8);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

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

Implementors§