pub struct OptionRangedUsize<const MIN: usize, const MAX: usize>(/* private fields */);
Expand description
An optional RangedUsize
; similar to Option<RangedUsize>
with better 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.
Sourcepub const fn get_primitive(self) -> Option<usize>
pub const fn get_primitive(self) -> Option<usize>
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 OptionRangedUsize::get_primitive_without_hint
.
Sourcepub const fn get_primitive_without_hint(self) -> Option<usize>
pub const fn get_primitive_without_hint(self) -> Option<usize>
Obtain the value of the struct as an Option
of the primitive type.
The returned value is identical to OptionRangedUsize::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: usize, const MAX: usize> Arbitrary for OptionRangedUsize<MIN, MAX>
Available on crate feature quickcheck
only.
impl<const MIN: usize, const MAX: usize> Arbitrary for OptionRangedUsize<MIN, MAX>
quickcheck
only.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<'de, const MIN: usize, const MAX: usize> Deserialize<'de> for OptionRangedUsize<MIN, MAX>
Available on crate feature serde
only.
impl<'de, const MIN: usize, const MAX: usize> Deserialize<'de> for OptionRangedUsize<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: usize, const MAX: usize> Distribution<OptionRangedUsize<MIN, MAX>> for Standard
Available on crate feature rand08
only.
impl<const MIN: usize, const MAX: usize> Distribution<OptionRangedUsize<MIN, MAX>> for Standard
rand08
only.Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OptionRangedUsize<MIN, MAX>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OptionRangedUsize<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: usize, const MAX: usize> Eq for OptionRangedUsize<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Eq for OptionRangedUsize<MIN, MAX>
#[doc(hidden)] fn assert_receiver_is_total_eq(&self)
Source§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>
Source§fn partial_cmp(
&self,
other: &OptionRangedUsize<MIN_B, MAX_B>,
) -> Option<Ordering>
fn partial_cmp( &self, other: &OptionRangedUsize<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: usize, const MAX: usize> Serialize for OptionRangedUsize<MIN, MAX>
Available on crate feature serde
only.
impl<const MIN: usize, const MAX: usize> Serialize for OptionRangedUsize<MIN, MAX>
serde
only.impl<const MIN: usize, const MAX: usize> Copy 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§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