[][src]Struct nonminmax::NonMinU64

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

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

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

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

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

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

Methods

impl NonMinU64[src]

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

Creates an instance of NonMinU64 by checking if the value is not u64::MIN.

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

Creates an instance of NonMinU64 without checking if the value is not u64::MIN.

Safety

The value cannot be equal to u64::MIN.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMinU64[src]

impl Copy for NonMinU64[src]

impl Debug for NonMinU64[src]

impl Display for NonMinU64[src]

impl Eq for NonMinU64[src]

impl From<NonMinU64> for u64[src]

impl Hash for NonMinU64[src]

impl Ord for NonMinU64[src]

impl PartialEq<NonMinU64> for NonMinU64[src]

impl PartialOrd<NonMinU64> for NonMinU64[src]

impl StructuralEq for NonMinU64[src]

impl StructuralPartialEq for NonMinU64[src]

Auto Trait Implementations

impl Send for NonMinU64

impl Sync for NonMinU64

impl Unpin for NonMinU64

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.