[][src]Struct nonminmax::NonMaxIsize

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

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

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

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

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

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

Methods

impl NonMaxIsize[src]

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

Creates an instance of NonMaxIsize by checking if the value is not isize::MAX.

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

Creates an instance of NonMaxIsize without checking if the value is not isize::MAX.

Safety

The value cannot be equal to isize::MAX.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMaxIsize[src]

impl Copy for NonMaxIsize[src]

impl Debug for NonMaxIsize[src]

impl Display for NonMaxIsize[src]

impl Eq for NonMaxIsize[src]

impl From<NonMaxIsize> for isize[src]

impl Hash for NonMaxIsize[src]

impl Ord for NonMaxIsize[src]

impl PartialEq<NonMaxIsize> for NonMaxIsize[src]

impl PartialOrd<NonMaxIsize> for NonMaxIsize[src]

impl StructuralEq for NonMaxIsize[src]

impl StructuralPartialEq for NonMaxIsize[src]

Auto Trait Implementations

impl Send for NonMaxIsize

impl Sync for NonMaxIsize

impl Unpin for NonMaxIsize

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.