[][src]Struct nonminmax::NonMinU128

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

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

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

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

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

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

Methods

impl NonMinU128[src]

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

Creates an instance of NonMinU128 by checking if the value is not u128::MIN.

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

Creates an instance of NonMinU128 without checking if the value is not u128::MIN.

Safety

The value cannot be equal to u128::MIN.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMinU128[src]

impl Copy for NonMinU128[src]

impl Debug for NonMinU128[src]

impl Display for NonMinU128[src]

impl Eq for NonMinU128[src]

impl From<NonMinU128> for u128[src]

impl Hash for NonMinU128[src]

impl Ord for NonMinU128[src]

impl PartialEq<NonMinU128> for NonMinU128[src]

impl PartialOrd<NonMinU128> for NonMinU128[src]

impl StructuralEq for NonMinU128[src]

impl StructuralPartialEq for NonMinU128[src]

Auto Trait Implementations

impl Send for NonMinU128

impl Sync for NonMinU128

impl Unpin for NonMinU128

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.