[][src]Struct nonminmax::NonMaxI128

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

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

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

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

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

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

Implementations

impl NonMaxI128[src]

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

Creates an instance of NonMaxI128 by checking if the value is not i128::MAX.

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

Creates an instance of NonMaxI128 without checking if the value is not i128::MAX.

Safety

The value cannot be equal to i128::MAX.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMaxI128[src]

impl Copy for NonMaxI128[src]

impl Debug for NonMaxI128[src]

impl Display for NonMaxI128[src]

impl Eq for NonMaxI128[src]

impl From<NonMaxI128> for i128[src]

impl Hash for NonMaxI128[src]

impl Ord for NonMaxI128[src]

impl PartialEq<NonMaxI128> for NonMaxI128[src]

impl PartialOrd<NonMaxI128> for NonMaxI128[src]

impl StructuralEq for NonMaxI128[src]

impl StructuralPartialEq for NonMaxI128[src]

Auto Trait Implementations

impl Send for NonMaxI128

impl Sync for NonMaxI128

impl Unpin for NonMaxI128

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.