[][src]Struct nonminmax::NonMinUsize

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

An integer of type usize which is known to not equal usize::MIN.

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

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

// The value cannot be `usize::MIN`
let y = NonMinUsize::new(usize::MIN);
assert_eq!(y, None);

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

Methods

impl NonMinUsize[src]

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

Creates an instance of NonMinUsize by checking if the value is not usize::MIN.

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

Creates an instance of NonMinUsize without checking if the value is not usize::MIN.

Safety

The value cannot be equal to usize::MIN.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMinUsize[src]

impl Copy for NonMinUsize[src]

impl Debug for NonMinUsize[src]

impl Display for NonMinUsize[src]

impl Eq for NonMinUsize[src]

impl From<NonMinUsize> for usize[src]

impl Hash for NonMinUsize[src]

impl Ord for NonMinUsize[src]

impl PartialEq<NonMinUsize> for NonMinUsize[src]

impl PartialOrd<NonMinUsize> for NonMinUsize[src]

impl StructuralEq for NonMinUsize[src]

impl StructuralPartialEq for NonMinUsize[src]

Auto Trait Implementations

impl Send for NonMinUsize

impl Sync for NonMinUsize

impl Unpin for NonMinUsize

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.