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