[][src]Struct nonminmax::NonMinI8

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

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

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

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

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

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

Methods

impl NonMinI8[src]

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

Creates an instance of NonMinI8 by checking if the value is not i8::MIN.

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

Creates an instance of NonMinI8 without checking if the value is not i8::MIN.

Safety

The value cannot be equal to i8::MIN.

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

Returns the integer value.

Trait Implementations

impl Clone for NonMinI8[src]

impl Copy for NonMinI8[src]

impl Debug for NonMinI8[src]

impl Display for NonMinI8[src]

impl Eq for NonMinI8[src]

impl From<NonMinI8> for i8[src]

impl Hash for NonMinI8[src]

impl Ord for NonMinI8[src]

impl PartialEq<NonMinI8> for NonMinI8[src]

impl PartialOrd<NonMinI8> for NonMinI8[src]

impl StructuralEq for NonMinI8[src]

impl StructuralPartialEq for NonMinI8[src]

Auto Trait Implementations

impl Send for NonMinI8

impl Sync for NonMinI8

impl Unpin for NonMinI8

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.