[][src]Struct nonminmax::NonMaxU128

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

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

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

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

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

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

Methods

impl NonMaxU128[src]

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

Creates an instance of NonMaxU128 by checking if the value is not u128::MAX.

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

Creates an instance of NonMaxU128 without checking if the value is not u128::MAX.

Safety

The value cannot be equal to u128::MAX.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMaxU128[src]

impl Copy for NonMaxU128[src]

impl Debug for NonMaxU128[src]

impl Display for NonMaxU128[src]

impl Eq for NonMaxU128[src]

impl From<NonMaxU128> for u128[src]

impl Hash for NonMaxU128[src]

impl Ord for NonMaxU128[src]

impl PartialEq<NonMaxU128> for NonMaxU128[src]

impl PartialOrd<NonMaxU128> for NonMaxU128[src]

impl StructuralEq for NonMaxU128[src]

impl StructuralPartialEq for NonMaxU128[src]

Auto Trait Implementations

impl Send for NonMaxU128

impl Sync for NonMaxU128

impl Unpin for NonMaxU128

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.