[][src]Struct nonminmax::NonMaxU16

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

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

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

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

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

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

Implementations

impl NonMaxU16[src]

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

Creates an instance of NonMaxU16 by checking if the value is not u16::MAX.

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

Creates an instance of NonMaxU16 without checking if the value is not u16::MAX.

Safety

The value cannot be equal to u16::MAX.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMaxU16[src]

impl Copy for NonMaxU16[src]

impl Debug for NonMaxU16[src]

impl Display for NonMaxU16[src]

impl Eq for NonMaxU16[src]

impl From<NonMaxU16> for u16[src]

impl Hash for NonMaxU16[src]

impl Ord for NonMaxU16[src]

impl PartialEq<NonMaxU16> for NonMaxU16[src]

impl PartialOrd<NonMaxU16> for NonMaxU16[src]

impl StructuralEq for NonMaxU16[src]

impl StructuralPartialEq for NonMaxU16[src]

Auto Trait Implementations

impl Send for NonMaxU16

impl Sync for NonMaxU16

impl Unpin for NonMaxU16

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.