Skip to main content

UnsignedPackable

Trait UnsignedPackable 

Source
pub trait UnsignedPackable: Sized {
    type Base: Copy;

    const BITS: usize;

    // Required methods
    fn from_unsigned(value: Self::Base) -> Self;
    fn to_unsigned(&self) -> Self::Base;
}
Expand description

A trait for any object that can be packed into and unpacked from an unsigned.

Required Associated Constants§

Source

const BITS: usize

The amount of bits which this type occupies in the base unsigned type. The occupied bits must always be the least significant N bits.

Required Associated Types§

Source

type Base: Copy

The unsigned base type that is used to store this type. Must be u8, u16, u32, u64 or u128. Must be able to hold at least Self::BITS bits.

Required Methods§

Source

fn from_unsigned(value: Self::Base) -> Self

Convert the base unsigned value into an instance of Self. Only the least significant Self::BITS bits have meaning, all other bits are guaranteed to be zero. This function must succeed for any given value.

Source

fn to_unsigned(&self) -> Self::Base

Convert this object into the base unsigned type. Only the least significant Self::BITS bits need to be well defined.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§