Trait smallnum::SmallUnsigned[][src]

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

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

Required methods

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

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.

Implementations on Foreign Types

Implementors