pub struct NonMinUsize { /* private fields */ }Expand description
An integer of type usize which is known to not equal usize::MIN.
This type allows for niche filling optimization (similar to the existing std::num::NonZero* types)
meaning items such as Option<NonMinUsize> and Result<NonMinUsize, ()> take up the same
amount of space as usize.
// Create using `new`, extract value using `get`
let x = NonMinUsize::new(123).unwrap();
assert_eq!(x.get(), 123);
// The value cannot be `usize::MIN`
let y = NonMinUsize::new(usize::MIN);
assert_eq!(y, None);
// Niche filling optimization works!
use std::mem::size_of;
assert_eq!(size_of::<usize>(), size_of::<NonMinUsize>());
assert_eq!(size_of::<usize>(), size_of::<Option<NonMinUsize>>());Implementations§
Source§impl NonMinUsize
impl NonMinUsize
Sourcepub fn new(value: usize) -> Option<Self>
pub fn new(value: usize) -> Option<Self>
Creates an instance of NonMinUsize by checking if the value is not usize::MIN.
Sourcepub unsafe fn new_unchecked(value: usize) -> Self
pub unsafe fn new_unchecked(value: usize) -> Self
Creates an instance of NonMinUsize without checking if the value is not usize::MIN.
§Safety
The value cannot be equal to usize::MIN.
Trait Implementations§
Source§impl Clone for NonMinUsize
impl Clone for NonMinUsize
Source§fn clone(&self) -> NonMinUsize
fn clone(&self) -> NonMinUsize
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NonMinUsize
impl Debug for NonMinUsize
Source§impl Display for NonMinUsize
impl Display for NonMinUsize
Source§impl From<NonMinUsize> for usize
impl From<NonMinUsize> for usize
Source§fn from(nontype: NonMinUsize) -> Self
fn from(nontype: NonMinUsize) -> Self
Converts to this type from the input type.
Source§impl Hash for NonMinUsize
impl Hash for NonMinUsize
Source§impl Ord for NonMinUsize
impl Ord for NonMinUsize
Source§fn cmp(&self, other: &NonMinUsize) -> Ordering
fn cmp(&self, other: &NonMinUsize) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for NonMinUsize
impl PartialEq for NonMinUsize
Source§impl PartialOrd for NonMinUsize
impl PartialOrd for NonMinUsize
impl Copy for NonMinUsize
impl Eq for NonMinUsize
impl StructuralPartialEq for NonMinUsize
Auto Trait Implementations§
impl Freeze for NonMinUsize
impl RefUnwindSafe for NonMinUsize
impl Send for NonMinUsize
impl Sync for NonMinUsize
impl Unpin for NonMinUsize
impl UnsafeUnpin for NonMinUsize
impl UnwindSafe for NonMinUsize
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more