[][src]Struct nonminmax::NonMaxU8

#[repr(transparent)]pub struct NonMaxU8 { /* fields omitted */ }

An integer of type u8 which is known to not equal u8::MAX.

This type allows for niche filling optimization (similar to the existing std::num::NonZero* types) meaning items such as Option<NonMaxU8> and Result<NonMaxU8, ()> take up the same amount of space as u8.

// Create using `new`, extract value using `get`
let x = NonMaxU8::new(123).unwrap();
assert_eq!(x.get(), 123);

// The value cannot be `u8::MAX`
let y = NonMaxU8::new(u8::MAX);
assert_eq!(y, None);

// Niche filling optimization works!
use std::mem::size_of;
assert_eq!(size_of::<u8>(), size_of::<NonMaxU8>());
assert_eq!(size_of::<u8>(), size_of::<Option<NonMaxU8>>());

Implementations

impl NonMaxU8[src]

pub fn new(value: u8) -> Option<Self>[src]

Creates an instance of NonMaxU8 by checking if the value is not u8::MAX.

pub unsafe fn new_unchecked(value: u8) -> Self[src]

Creates an instance of NonMaxU8 without checking if the value is not u8::MAX.

Safety

The value cannot be equal to u8::MAX.

pub fn get(self) -> u8[src]

Returns the integer value.

Trait Implementations

impl Clone for NonMaxU8[src]

impl Copy for NonMaxU8[src]

impl Debug for NonMaxU8[src]

impl Display for NonMaxU8[src]

impl Eq for NonMaxU8[src]

impl From<NonMaxU8> for u8[src]

impl Hash for NonMaxU8[src]

impl Ord for NonMaxU8[src]

impl PartialEq<NonMaxU8> for NonMaxU8[src]

impl PartialOrd<NonMaxU8> for NonMaxU8[src]

impl StructuralEq for NonMaxU8[src]

impl StructuralPartialEq for NonMaxU8[src]

Auto Trait Implementations

impl Send for NonMaxU8

impl Sync for NonMaxU8

impl Unpin for NonMaxU8

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.