pub struct OptionRangedUsize<const MIN: usize, const MAX: usize>(/* private fields */);
Expand description
A RangedUsize
that is optional. Equivalent to Option<RangedUsize>
with niche value optimization.
If MIN
is usize::MIN
and MAX
is usize::MAX
then compilation will fail. This is because there is no way to represent the niche value.
This type is useful when you need to store an optional ranged value in a struct, but
do not want the overhead of an Option
type. This reduces the size of the struct
overall, and is particularly useful when you have a large number of optional fields.
Note that most operations must still be performed on the Option
type, which is
obtained with OptionRangedUsize::get
.
Implementations§
source§impl<const MIN: usize, const MAX: usize> OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> OptionRangedUsize<MIN, MAX>
sourcepub const fn Some(value: RangedUsize<MIN, MAX>) -> Self
pub const fn Some(value: RangedUsize<MIN, MAX>) -> Self
Creates an optional ranged value that is present.
sourcepub const fn get(self) -> Option<RangedUsize<MIN, MAX>>
pub const fn get(self) -> Option<RangedUsize<MIN, MAX>>
Returns the value as the standard library’s Option
type.
sourcepub const unsafe fn some_unchecked(value: usize) -> Self
pub const unsafe fn some_unchecked(value: usize) -> Self
Creates an optional ranged integer without checking the value.
§Safety
The value must be within the range MIN..=MAX
. As the value used for niche
value optimization is unspecified, the provided value must not be the niche
value.
source§impl<const MIN: usize, const MAX: usize> OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> OptionRangedUsize<MIN, MAX>
Trait Implementations§
source§impl<const MIN: usize, const MAX: usize> Clone for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Clone for OptionRangedUsize<MIN, MAX>
source§fn clone(&self) -> OptionRangedUsize<MIN, MAX>
fn clone(&self) -> OptionRangedUsize<MIN, MAX>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<const MIN: usize, const MAX: usize> From<Option<RangedUsize<MIN, MAX>>> for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> From<Option<RangedUsize<MIN, MAX>>> for OptionRangedUsize<MIN, MAX>
source§fn from(value: Option<RangedUsize<MIN, MAX>>) -> Self
fn from(value: Option<RangedUsize<MIN, MAX>>) -> Self
source§impl<const MIN: usize, const MAX: usize> From<OptionRangedUsize<MIN, MAX>> for Option<RangedUsize<MIN, MAX>>
impl<const MIN: usize, const MAX: usize> From<OptionRangedUsize<MIN, MAX>> for Option<RangedUsize<MIN, MAX>>
source§fn from(value: OptionRangedUsize<MIN, MAX>) -> Self
fn from(value: OptionRangedUsize<MIN, MAX>) -> Self
source§impl<const MIN: usize, const MAX: usize> From<RangedUsize<MIN, MAX>> for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> From<RangedUsize<MIN, MAX>> for OptionRangedUsize<MIN, MAX>
source§fn from(value: RangedUsize<MIN, MAX>) -> Self
fn from(value: RangedUsize<MIN, MAX>) -> Self
source§impl<const MIN: usize, const MAX: usize> Ord for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Ord for OptionRangedUsize<MIN, MAX>
source§impl<const MIN_A: usize, const MAX_A: usize, const MIN_B: usize, const MAX_B: usize> PartialEq<OptionRangedUsize<MIN_B, MAX_B>> for OptionRangedUsize<MIN_A, MAX_A>
impl<const MIN_A: usize, const MAX_A: usize, const MIN_B: usize, const MAX_B: usize> PartialEq<OptionRangedUsize<MIN_B, MAX_B>> for OptionRangedUsize<MIN_A, MAX_A>
source§fn eq(&self, other: &OptionRangedUsize<MIN_B, MAX_B>) -> bool
fn eq(&self, other: &OptionRangedUsize<MIN_B, MAX_B>) -> bool
self
and other
values to be equal, and is used by ==
.source§impl<const MIN_A: usize, const MAX_A: usize, const MIN_B: usize, const MAX_B: usize> PartialOrd<OptionRangedUsize<MIN_B, MAX_B>> for OptionRangedUsize<MIN_A, MAX_A>
impl<const MIN_A: usize, const MAX_A: usize, const MIN_B: usize, const MAX_B: usize> PartialOrd<OptionRangedUsize<MIN_B, MAX_B>> for OptionRangedUsize<MIN_A, MAX_A>
impl<const MIN: usize, const MAX: usize> Copy for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Eq for OptionRangedUsize<MIN, MAX>
Auto Trait Implementations§
impl<const MIN: usize, const MAX: usize> Freeze for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> RefUnwindSafe for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Send for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Sync for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Unpin for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> UnwindSafe for OptionRangedUsize<MIN, MAX>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)