pub struct OptionRangedU64<const MIN: u64, const MAX: u64>(/* private fields */);
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
.
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 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.
A call to this function will output a hint to the compiler that the value is in
range. In general this will help the optimizer to generate better code, but in edge
cases this may lead to worse code generation. To avoid outputting the hint, you can
use OptionRangedU64::get_primitive_without_hint
.
Sourcepub const fn get_primitive_without_hint(self) -> Option<u64>
pub const fn get_primitive_without_hint(self) -> Option<u64>
Obtain the value of the struct as an Option
of the primitive type.
The returned value is identical to OptionRangedU64::get_primitive
.
Unlike get_primitive
, no hints are output to the compiler indicating the range
that the value is in. Depending on the scenario, this may with be helpful or harmful
too optimization.
Trait Implementations§
Source§impl<const MIN: u64, const MAX: u64> Arbitrary for OptionRangedU64<MIN, MAX>
Available on crate feature quickcheck
only.
impl<const MIN: u64, const MAX: u64> Arbitrary for OptionRangedU64<MIN, MAX>
quickcheck
only.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>
Available on crate feature serde
only.
impl<'de, const MIN: u64, const MAX: u64> Deserialize<'de> for OptionRangedU64<MIN, MAX>
serde
only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
self
from the given Deserializer. Read moreSource§impl<const MIN: u64, const MAX: u64> Distribution<OptionRangedU64<MIN, MAX>> for Standard
Available on crate feature rand08
only.
impl<const MIN: u64, const MAX: u64> Distribution<OptionRangedU64<MIN, MAX>> for Standard
rand08
only.Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OptionRangedU64<MIN, MAX>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OptionRangedU64<MIN, MAX>
T
, using rng
as the source of randomness.Source§fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
T
, using rng
as
the source of randomness. Read moreSource§impl<const MIN: u64, const MAX: u64> Eq for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> Eq for OptionRangedU64<MIN, MAX>
#[doc(hidden)] fn assert_receiver_is_total_eq(&self)
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 ==
.Source§impl<const MIN_A: u64, const MAX_A: u64, const MIN_B: u64, const MAX_B: u64> PartialOrd<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> PartialOrd<OptionRangedU64<MIN_B, MAX_B>> for OptionRangedU64<MIN_A, MAX_A>
Source§fn partial_cmp(&self, other: &OptionRangedU64<MIN_B, MAX_B>) -> Option<Ordering>
fn partial_cmp(&self, other: &OptionRangedU64<MIN_B, MAX_B>) -> Option<Ordering>
Source§#[doc(hidden)] fn __chaining_lt(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_lt(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods
)self == other
, returns ControlFlow::Continue(())
.
Otherwise, returns ControlFlow::Break(self < other)
. Read moreSource§#[doc(hidden)] fn __chaining_le(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_le(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods
)__chaining_lt
, but for <=
instead of <
.Source§#[doc(hidden)] fn __chaining_gt(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_gt(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods
)__chaining_lt
, but for >
instead of <
.Source§#[doc(hidden)] fn __chaining_ge(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_ge(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods
)__chaining_lt
, but for >=
instead of <
.Source§impl<const MIN: u64, const MAX: u64> Serialize for OptionRangedU64<MIN, MAX>
Available on crate feature serde
only.
impl<const MIN: u64, const MAX: u64> Serialize for OptionRangedU64<MIN, MAX>
serde
only.impl<const MIN: u64, const MAX: u64> Copy for OptionRangedU64<MIN, MAX>
Auto Trait Implementations§
impl<const MIN: u64, const MAX: u64> Freeze for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> RefUnwindSafe for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> Send for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> Sync for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> Unpin for OptionRangedU64<MIN, MAX>
impl<const MIN: u64, const MAX: u64> UnwindSafe for OptionRangedU64<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§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties
)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties
)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties
)[Self]
. Read more