#[repr(transparent)]pub struct OptionRangedU64<const MIN: u64, const MAX: u64>(pub(crate) u64);
Expand description
An optional RangedU64
; similar to Option<RangedU64>
with better optimization.
If MIN
is u64::MIN
and MAX
is u64::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 OptionRangedU64::get
.
Tuple Fields§
§0: u64
Implementations§
Source§impl<const MIN: u64, const MAX: u64> OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> OptionRangedU64<MIN, MAX>
Sourcepub const fn Some(value: RangedU64<MIN, MAX>) -> Self
pub const fn Some(value: RangedU64<MIN, MAX>) -> Self
Creates an optional ranged value that is present.
Sourcepub const fn get(self) -> Option<RangedU64<MIN, MAX>>
pub const fn get(self) -> Option<RangedU64<MIN, MAX>>
Returns the value as the standard library’s Option
type.
Sourcepub const unsafe fn some_unchecked(value: u64) -> Self
pub const unsafe fn some_unchecked(value: u64) -> 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.
Sourcepub(crate) const fn inner(self) -> u64
pub(crate) const fn inner(self) -> u64
Obtain the inner value of the struct. This is useful for comparisons.
Sourcepub const fn get_primitive(self) -> Option<u64>
pub const fn get_primitive(self) -> Option<u64>
Obtain the value of the struct as an Option
of the primitive type.
Trait Implementations§
Source§impl<const MIN: u64, const MAX: u64> Clone for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> Clone for OptionRangedU64<MIN, MAX>
Source§fn clone(&self) -> OptionRangedU64<MIN, MAX>
fn clone(&self) -> OptionRangedU64<MIN, MAX>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'de, const MIN: u64, const MAX: u64> Deserialize<'de> for OptionRangedU64<MIN, MAX>
impl<'de, const MIN: u64, const MAX: u64> Deserialize<'de> for OptionRangedU64<MIN, MAX>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<const MIN: u64, const MAX: u64> From<Option<RangedU64<MIN, MAX>>> for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> From<Option<RangedU64<MIN, MAX>>> for OptionRangedU64<MIN, MAX>
Source§impl<const MIN: u64, const MAX: u64> From<OptionRangedU64<MIN, MAX>> for Option<RangedU64<MIN, MAX>>
impl<const MIN: u64, const MAX: u64> From<OptionRangedU64<MIN, MAX>> for Option<RangedU64<MIN, MAX>>
Source§fn from(value: OptionRangedU64<MIN, MAX>) -> Self
fn from(value: OptionRangedU64<MIN, MAX>) -> Self
Source§impl<const MIN: u64, const MAX: u64> Ord for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> Ord for OptionRangedU64<MIN, MAX>
Source§impl<const MIN_A: u64, const MAX_A: u64, const MIN_B: u64, const MAX_B: u64> PartialEq<OptionRangedU64<MIN_B, MAX_B>> for OptionRangedU64<MIN_A, MAX_A>
impl<const MIN_A: u64, const MAX_A: u64, const MIN_B: u64, const MAX_B: u64> PartialEq<OptionRangedU64<MIN_B, MAX_B>> for OptionRangedU64<MIN_A, MAX_A>
Source§fn eq(&self, other: &OptionRangedU64<MIN_B, MAX_B>) -> bool
fn eq(&self, other: &OptionRangedU64<MIN_B, MAX_B>) -> bool
self
and other
values to be equal, and is used by ==
.