[][src]Struct nonminmax::NonMaxI32

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

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

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

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

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

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

Methods

impl NonMaxI32[src]

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

Creates an instance of NonMaxI32 by checking if the value is not i32::MAX.

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

Creates an instance of NonMaxI32 without checking if the value is not i32::MAX.

Safety

The value cannot be equal to i32::MAX.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMaxI32[src]

impl Copy for NonMaxI32[src]

impl Debug for NonMaxI32[src]

impl Display for NonMaxI32[src]

impl Eq for NonMaxI32[src]

impl From<NonMaxI32> for i32[src]

impl Hash for NonMaxI32[src]

impl Ord for NonMaxI32[src]

impl PartialEq<NonMaxI32> for NonMaxI32[src]

impl PartialOrd<NonMaxI32> for NonMaxI32[src]

impl StructuralEq for NonMaxI32[src]

impl StructuralPartialEq for NonMaxI32[src]

Auto Trait Implementations

impl Send for NonMaxI32

impl Sync for NonMaxI32

impl Unpin for NonMaxI32

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.