[][src]Struct nonminmax::NonMinIsize

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

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

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

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

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

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

Implementations

impl NonMinIsize[src]

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

Creates an instance of NonMinIsize by checking if the value is not isize::MIN.

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

Creates an instance of NonMinIsize without checking if the value is not isize::MIN.

Safety

The value cannot be equal to isize::MIN.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMinIsize[src]

impl Copy for NonMinIsize[src]

impl Debug for NonMinIsize[src]

impl Display for NonMinIsize[src]

impl Eq for NonMinIsize[src]

impl From<NonMinIsize> for isize[src]

impl Hash for NonMinIsize[src]

impl Ord for NonMinIsize[src]

impl PartialEq<NonMinIsize> for NonMinIsize[src]

impl PartialOrd<NonMinIsize> for NonMinIsize[src]

impl StructuralEq for NonMinIsize[src]

impl StructuralPartialEq for NonMinIsize[src]

Auto Trait Implementations

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.