Struct deranged::OptionRangedU8
source · #[repr(transparent)]pub struct OptionRangedU8<const MIN: u8, const MAX: u8>(pub(crate) u8);
Expand description
A RangedU8
that is optional. Equivalent to Option<RangedU8>
with niche value optimization.
If MIN
is u8::MIN
and MAX
is u8::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 OptionRangedU8::get
.
Tuple Fields§
§0: u8
Implementations§
source§impl<const MIN: u8, const MAX: u8> OptionRangedU8<MIN, MAX>
impl<const MIN: u8, const MAX: u8> OptionRangedU8<MIN, MAX>
sourcepub(crate) const NICHE: u8 = _
pub(crate) const NICHE: u8 = _
The value used as the niche. Must not be in the range MIN..=MAX
.
sourcepub const fn Some(value: RangedU8<MIN, MAX>) -> Self
pub const fn Some(value: RangedU8<MIN, MAX>) -> Self
Creates an optional ranged value that is present.
sourcepub const fn get(self) -> Option<RangedU8<MIN, MAX>>
pub const fn get(self) -> Option<RangedU8<MIN, MAX>>
Returns the value as the standard library’s Option
type.
sourcepub const unsafe fn some_unchecked(value: u8) -> Self
pub const unsafe fn some_unchecked(value: u8) -> 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) -> u8
pub(crate) const fn inner(self) -> u8
Obtain the inner value of the struct. This is useful for comparisons.
pub const fn get_primitive(self) -> Option<u8>
Trait Implementations§
source§impl<const MIN: u8, const MAX: u8> Clone for OptionRangedU8<MIN, MAX>
impl<const MIN: u8, const MAX: u8> Clone for OptionRangedU8<MIN, MAX>
source§fn clone(&self) -> OptionRangedU8<MIN, MAX>
fn clone(&self) -> OptionRangedU8<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: u8, const MAX: u8> Deserialize<'de> for OptionRangedU8<MIN, MAX>
impl<'de, const MIN: u8, const MAX: u8> Deserialize<'de> for OptionRangedU8<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: u8, const MAX: u8> From<Option<RangedU8<MIN, MAX>>> for OptionRangedU8<MIN, MAX>
impl<const MIN: u8, const MAX: u8> From<Option<RangedU8<MIN, MAX>>> for OptionRangedU8<MIN, MAX>
source§impl<const MIN: u8, const MAX: u8> From<OptionRangedU8<MIN, MAX>> for Option<RangedU8<MIN, MAX>>
impl<const MIN: u8, const MAX: u8> From<OptionRangedU8<MIN, MAX>> for Option<RangedU8<MIN, MAX>>
source§fn from(value: OptionRangedU8<MIN, MAX>) -> Self
fn from(value: OptionRangedU8<MIN, MAX>) -> Self
source§impl<const MIN: u8, const MAX: u8> Ord for OptionRangedU8<MIN, MAX>
impl<const MIN: u8, const MAX: u8> Ord for OptionRangedU8<MIN, MAX>
source§impl<const MIN_A: u8, const MAX_A: u8, const MIN_B: u8, const MAX_B: u8> PartialEq<OptionRangedU8<MIN_B, MAX_B>> for OptionRangedU8<MIN_A, MAX_A>
impl<const MIN_A: u8, const MAX_A: u8, const MIN_B: u8, const MAX_B: u8> PartialEq<OptionRangedU8<MIN_B, MAX_B>> for OptionRangedU8<MIN_A, MAX_A>
source§fn eq(&self, other: &OptionRangedU8<MIN_B, MAX_B>) -> bool
fn eq(&self, other: &OptionRangedU8<MIN_B, MAX_B>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<const MIN_A: u8, const MAX_A: u8, const MIN_B: u8, const MAX_B: u8> PartialOrd<OptionRangedU8<MIN_B, MAX_B>> for OptionRangedU8<MIN_A, MAX_A>
impl<const MIN_A: u8, const MAX_A: u8, const MIN_B: u8, const MAX_B: u8> PartialOrd<OptionRangedU8<MIN_B, MAX_B>> for OptionRangedU8<MIN_A, MAX_A>
source§fn partial_cmp(&self, other: &OptionRangedU8<MIN_B, MAX_B>) -> Option<Ordering>
fn partial_cmp(&self, other: &OptionRangedU8<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 more