[][src]Struct nonminmax::NonMaxI16

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

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

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

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

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

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

Methods

impl NonMaxI16[src]

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

Creates an instance of NonMaxI16 by checking if the value is not i16::MAX.

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

Creates an instance of NonMaxI16 without checking if the value is not i16::MAX.

Safety

The value cannot be equal to i16::MAX.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMaxI16[src]

impl Copy for NonMaxI16[src]

impl Debug for NonMaxI16[src]

impl Display for NonMaxI16[src]

impl Eq for NonMaxI16[src]

impl From<NonMaxI16> for i16[src]

impl Hash for NonMaxI16[src]

impl Ord for NonMaxI16[src]

impl PartialEq<NonMaxI16> for NonMaxI16[src]

impl PartialOrd<NonMaxI16> for NonMaxI16[src]

impl StructuralEq for NonMaxI16[src]

impl StructuralPartialEq for NonMaxI16[src]

Auto Trait Implementations

impl Send for NonMaxI16

impl Sync for NonMaxI16

impl Unpin for NonMaxI16

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.