[−][src]Struct nonminmax::NonMinU16
An integer of type u16
which is known to not equal u16::MIN
.
This type allows for niche filling optimization (similar to the existing std::num::NonZero*
types)
meaning items such as Option<NonMinU16>
and Result<NonMinU16, ()>
take up the same
amount of space as u16
.
// Create using `new`, extract value using `get` let x = NonMinU16::new(123).unwrap(); assert_eq!(x.get(), 123); // The value cannot be `u16::MIN` let y = NonMinU16::new(u16::MIN); assert_eq!(y, None); // Niche filling optimization works! use std::mem::size_of; assert_eq!(size_of::<u16>(), size_of::<NonMinU16>()); assert_eq!(size_of::<u16>(), size_of::<Option<NonMinU16>>());
Methods
impl NonMinU16
[src]
pub fn new(value: u16) -> Option<Self>
[src]
Creates an instance of NonMinU16
by checking if the value is not u16::MIN
.
pub unsafe fn new_unchecked(value: u16) -> Self
[src]
Creates an instance of NonMinU16
without checking if the value is not u16::MIN
.
Safety
The value cannot be equal to u16::MIN
.
pub fn get(self) -> u16
[src]
Returns the integer value.
Trait Implementations
impl Clone for NonMinU16
[src]
fn clone(&self) -> NonMinU16
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for NonMinU16
[src]
impl Debug for NonMinU16
[src]
impl Display for NonMinU16
[src]
impl Eq for NonMinU16
[src]
impl From<NonMinU16> for u16
[src]
impl Hash for NonMinU16
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for NonMinU16
[src]
fn cmp(&self, other: &NonMinU16) -> Ordering
[src]
#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<NonMinU16> for NonMinU16
[src]
impl PartialOrd<NonMinU16> for NonMinU16
[src]
fn partial_cmp(&self, other: &NonMinU16) -> Option<Ordering>
[src]
fn lt(&self, other: &NonMinU16) -> bool
[src]
fn le(&self, other: &NonMinU16) -> bool
[src]
fn gt(&self, other: &NonMinU16) -> bool
[src]
fn ge(&self, other: &NonMinU16) -> bool
[src]
impl StructuralEq for NonMinU16
[src]
impl StructuralPartialEq for NonMinU16
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,