Trait Unsigned

Source
pub trait Unsigned:
    Sized
    + Copy
    + Shr<u32, Output = Self>
    + Shl<u32, Output = Self>
    + BitXor<Self, Output = Self>
    + BitAnd<Self, Output = Self>
    + PartialOrd<Self>
    + Ord {
    type Signed: Signed;

    const ONE: Self;
    const BYTES: u8;

    // Required methods
    fn signed(self) -> Self::Signed;
    fn from_byte(byte: u8) -> Self;
    fn as_byte(self) -> u8;
    fn is_smaller_than(self, byte: u8) -> bool;
    fn is_zero(self) -> bool;
    fn checked_shr(self, value: u32) -> Option<Self>;
    fn checked_shl(self, value: u32) -> Option<Self>;
    fn checked_add(self, value: Self) -> Option<Self>;
}
Expand description

Trait that encodes common behaviors of unsigned numbers.

Required Associated Constants§

Source

const ONE: Self

The number 1 as represented by the current unsigned number.

Source

const BYTES: u8

Number of bytes.

Required Associated Types§

Source

type Signed: Signed

The signed representation of this unsigned number.

Required Methods§

Source

fn signed(self) -> Self::Signed

Coerce this number bitwise into its signed representation.

Source

fn from_byte(byte: u8) -> Self

Construct from the first byte.

Source

fn as_byte(self) -> u8

Coerce into the lowest 8-bits as a byte.

Source

fn is_smaller_than(self, byte: u8) -> bool

Test if this value is smaller than the specified byte.

Source

fn is_zero(self) -> bool

Test if value is zero.

Source

fn checked_shr(self, value: u32) -> Option<Self>

Perform a shift-right operation.

Source

fn checked_shl(self, value: u32) -> Option<Self>

Perform a shift-left operation.

Source

fn checked_add(self, value: Self) -> Option<Self>

Perform a checked addition.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Unsigned for u16

Source§

const ONE: Self = 1u16

Source§

const BYTES: u8 = 2u8

Source§

type Signed = i16

Source§

fn signed(self) -> Self::Signed

Source§

fn from_byte(byte: u8) -> Self

Source§

fn as_byte(self) -> u8

Source§

fn is_smaller_than(self, b: u8) -> bool

Source§

fn is_zero(self) -> bool

Source§

fn checked_shr(self, value: u32) -> Option<Self>

Source§

fn checked_shl(self, value: u32) -> Option<Self>

Source§

fn checked_add(self, value: Self) -> Option<Self>

Source§

impl Unsigned for u32

Source§

const ONE: Self = 1u32

Source§

const BYTES: u8 = 4u8

Source§

type Signed = i32

Source§

fn signed(self) -> Self::Signed

Source§

fn from_byte(byte: u8) -> Self

Source§

fn as_byte(self) -> u8

Source§

fn is_smaller_than(self, b: u8) -> bool

Source§

fn is_zero(self) -> bool

Source§

fn checked_shr(self, value: u32) -> Option<Self>

Source§

fn checked_shl(self, value: u32) -> Option<Self>

Source§

fn checked_add(self, value: Self) -> Option<Self>

Source§

impl Unsigned for u64

Source§

const ONE: Self = 1u64

Source§

const BYTES: u8 = 8u8

Source§

type Signed = i64

Source§

fn signed(self) -> Self::Signed

Source§

fn from_byte(byte: u8) -> Self

Source§

fn as_byte(self) -> u8

Source§

fn is_smaller_than(self, b: u8) -> bool

Source§

fn is_zero(self) -> bool

Source§

fn checked_shr(self, value: u32) -> Option<Self>

Source§

fn checked_shl(self, value: u32) -> Option<Self>

Source§

fn checked_add(self, value: Self) -> Option<Self>

Source§

impl Unsigned for u128

Source§

const ONE: Self = 1u128

Source§

const BYTES: u8 = 16u8

Source§

type Signed = i128

Source§

fn signed(self) -> Self::Signed

Source§

fn from_byte(byte: u8) -> Self

Source§

fn as_byte(self) -> u8

Source§

fn is_smaller_than(self, b: u8) -> bool

Source§

fn is_zero(self) -> bool

Source§

fn checked_shr(self, value: u32) -> Option<Self>

Source§

fn checked_shl(self, value: u32) -> Option<Self>

Source§

fn checked_add(self, value: Self) -> Option<Self>

Source§

impl Unsigned for usize

Source§

const ONE: Self = 1usize

Source§

const BYTES: u8 = 8u8

Source§

type Signed = isize

Source§

fn signed(self) -> Self::Signed

Source§

fn from_byte(byte: u8) -> Self

Source§

fn as_byte(self) -> u8

Source§

fn is_smaller_than(self, b: u8) -> bool

Source§

fn is_zero(self) -> bool

Source§

fn checked_shr(self, value: u32) -> Option<Self>

Source§

fn checked_shl(self, value: u32) -> Option<Self>

Source§

fn checked_add(self, value: Self) -> Option<Self>

Implementors§