[−][src]Struct nonminmax::NonMaxIsize
An integer of type isize
which is known to not equal isize::MAX
.
This type allows for niche filling optimization (similar to the existing std::num::NonZero*
types)
meaning items such as Option<NonMaxIsize>
and Result<NonMaxIsize, ()>
take up the same
amount of space as isize
.
// Create using `new`, extract value using `get` let x = NonMaxIsize::new(123).unwrap(); assert_eq!(x.get(), 123); // The value cannot be `isize::MAX` let y = NonMaxIsize::new(isize::MAX); assert_eq!(y, None); // Niche filling optimization works! use std::mem::size_of; assert_eq!(size_of::<isize>(), size_of::<NonMaxIsize>()); assert_eq!(size_of::<isize>(), size_of::<Option<NonMaxIsize>>());
Methods
impl NonMaxIsize
[src]
pub fn new(value: isize) -> Option<Self>
[src]
Creates an instance of NonMaxIsize
by checking if the value is not isize::MAX
.
pub unsafe fn new_unchecked(value: isize) -> Self
[src]
Creates an instance of NonMaxIsize
without checking if the value is not isize::MAX
.
Safety
The value cannot be equal to isize::MAX
.
pub fn get(self) -> isize
[src]
Returns the integer value.
Trait Implementations
impl Clone for NonMaxIsize
[src]
fn clone(&self) -> NonMaxIsize
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for NonMaxIsize
[src]
impl Debug for NonMaxIsize
[src]
impl Display for NonMaxIsize
[src]
impl Eq for NonMaxIsize
[src]
impl From<NonMaxIsize> for isize
[src]
fn from(nontype: NonMaxIsize) -> Self
[src]
impl Hash for NonMaxIsize
[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 NonMaxIsize
[src]
fn cmp(&self, other: &NonMaxIsize) -> 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<NonMaxIsize> for NonMaxIsize
[src]
fn eq(&self, other: &NonMaxIsize) -> bool
[src]
fn ne(&self, other: &NonMaxIsize) -> bool
[src]
impl PartialOrd<NonMaxIsize> for NonMaxIsize
[src]
fn partial_cmp(&self, other: &NonMaxIsize) -> Option<Ordering>
[src]
fn lt(&self, other: &NonMaxIsize) -> bool
[src]
fn le(&self, other: &NonMaxIsize) -> bool
[src]
fn gt(&self, other: &NonMaxIsize) -> bool
[src]
fn ge(&self, other: &NonMaxIsize) -> bool
[src]
impl StructuralEq for NonMaxIsize
[src]
impl StructuralPartialEq for NonMaxIsize
[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>,