Struct deranged::OptionRangedIsize
source · pub struct OptionRangedIsize<const MIN: isize, const MAX: isize>(/* private fields */);
Expand description
A RangedIsize
that is optional. Equivalent to Option<RangedIsize>
with niche value optimization.
If MIN
is isize::MIN
and MAX
is isize::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 OptionRangedIsize::get
.
Implementations§
source§impl<const MIN: isize, const MAX: isize> OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> OptionRangedIsize<MIN, MAX>
sourcepub const fn Some(value: RangedIsize<MIN, MAX>) -> Self
pub const fn Some(value: RangedIsize<MIN, MAX>) -> Self
Creates an optional ranged value that is present.
sourcepub const fn get(self) -> Option<RangedIsize<MIN, MAX>>
pub const fn get(self) -> Option<RangedIsize<MIN, MAX>>
Returns the value as the standard library’s Option
type.
sourcepub const unsafe fn some_unchecked(value: isize) -> Self
pub const unsafe fn some_unchecked(value: isize) -> 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.
pub const fn get_primitive(self) -> Option<isize>
Trait Implementations§
source§impl<const MIN: isize, const MAX: isize> Clone for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> Clone for OptionRangedIsize<MIN, MAX>
source§fn clone(&self) -> OptionRangedIsize<MIN, MAX>
fn clone(&self) -> OptionRangedIsize<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: isize, const MAX: isize> From<Option<RangedIsize<MIN, MAX>>> for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> From<Option<RangedIsize<MIN, MAX>>> for OptionRangedIsize<MIN, MAX>
source§fn from(value: Option<RangedIsize<MIN, MAX>>) -> Self
fn from(value: Option<RangedIsize<MIN, MAX>>) -> Self
source§impl<const MIN: isize, const MAX: isize> From<OptionRangedIsize<MIN, MAX>> for Option<RangedIsize<MIN, MAX>>
impl<const MIN: isize, const MAX: isize> From<OptionRangedIsize<MIN, MAX>> for Option<RangedIsize<MIN, MAX>>
source§fn from(value: OptionRangedIsize<MIN, MAX>) -> Self
fn from(value: OptionRangedIsize<MIN, MAX>) -> Self
source§impl<const MIN: isize, const MAX: isize> From<RangedIsize<MIN, MAX>> for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> From<RangedIsize<MIN, MAX>> for OptionRangedIsize<MIN, MAX>
source§fn from(value: RangedIsize<MIN, MAX>) -> Self
fn from(value: RangedIsize<MIN, MAX>) -> Self
source§impl<const MIN: isize, const MAX: isize> Ord for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> Ord for OptionRangedIsize<MIN, MAX>
source§impl<const MIN_A: isize, const MAX_A: isize, const MIN_B: isize, const MAX_B: isize> PartialEq<OptionRangedIsize<MIN_B, MAX_B>> for OptionRangedIsize<MIN_A, MAX_A>
impl<const MIN_A: isize, const MAX_A: isize, const MIN_B: isize, const MAX_B: isize> PartialEq<OptionRangedIsize<MIN_B, MAX_B>> for OptionRangedIsize<MIN_A, MAX_A>
source§fn eq(&self, other: &OptionRangedIsize<MIN_B, MAX_B>) -> bool
fn eq(&self, other: &OptionRangedIsize<MIN_B, MAX_B>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<const MIN_A: isize, const MAX_A: isize, const MIN_B: isize, const MAX_B: isize> PartialOrd<OptionRangedIsize<MIN_B, MAX_B>> for OptionRangedIsize<MIN_A, MAX_A>
impl<const MIN_A: isize, const MAX_A: isize, const MIN_B: isize, const MAX_B: isize> PartialOrd<OptionRangedIsize<MIN_B, MAX_B>> for OptionRangedIsize<MIN_A, MAX_A>
source§fn partial_cmp(
&self,
other: &OptionRangedIsize<MIN_B, MAX_B>,
) -> Option<Ordering>
fn partial_cmp( &self, other: &OptionRangedIsize<MIN_B, MAX_B>, ) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<const MIN: isize, const MAX: isize> Copy for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> Eq for OptionRangedIsize<MIN, MAX>
Auto Trait Implementations§
impl<const MIN: isize, const MAX: isize> Freeze for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> RefUnwindSafe for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> Send for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> Sync for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> Unpin for OptionRangedIsize<MIN, MAX>
impl<const MIN: isize, const MAX: isize> UnwindSafe for OptionRangedIsize<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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)