SmallUnsigned

Trait SmallUnsigned 

Source
pub trait SmallUnsigned {
    // Required methods
    fn usize(&self) -> usize;
    fn checked_from(num: usize) -> Self;
}
Expand description

Convenience trait for unsigned normalization (e.g. to/from usize).

Required Methods§

Source

fn usize(&self) -> usize

Upcast: Get value of small unsigned as host register-width unsigned (e.g. usize)

Source

fn checked_from(num: usize) -> Self

Downcast: Convert input usize into a primitive implementing the SmallUnsigned trait. Panics if usize exceeds max for returned unsigned primitive. core::convert::From not used b/c SmallUnsigned is not generic by design, implemented only for (u8, u16, u32, u64, u128) and only up to host integer width.

§Note

Unlike others, this API has a tiny (1 comparison/branch) runtime cost. The check in checked_from is an assert to prevent loss of precision.

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 SmallUnsigned for u8

Source§

impl SmallUnsigned for u16

Source§

impl SmallUnsigned for u32

Source§

impl SmallUnsigned for usize

Implementors§