pub struct OptionRangedI64<const MIN: i64, const MAX: i64>(/* private fields */);
Expand description
A RangedI64
that is optional. Equivalent to Option<RangedI64>
with niche value optimization.
If MIN
is i64::MIN
and MAX
is i64::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 OptionRangedI64::get
.
Implementations§
Source§impl<const MIN: i64, const MAX: i64> OptionRangedI64<MIN, MAX>
impl<const MIN: i64, const MAX: i64> OptionRangedI64<MIN, MAX>
Sourcepub const fn Some(value: RangedI64<MIN, MAX>) -> Self
pub const fn Some(value: RangedI64<MIN, MAX>) -> Self
Creates an optional ranged value that is present.
Sourcepub const fn get(self) -> Option<RangedI64<MIN, MAX>>
pub const fn get(self) -> Option<RangedI64<MIN, MAX>>
Returns the value as the standard library’s Option
type.
Sourcepub const unsafe fn some_unchecked(value: i64) -> Self
pub const unsafe fn some_unchecked(value: i64) -> 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<i64>
Trait Implementations§
Source§impl<const MIN: i64, const MAX: i64> Clone for OptionRangedI64<MIN, MAX>
impl<const MIN: i64, const MAX: i64> Clone for OptionRangedI64<MIN, MAX>
Source§fn clone(&self) -> OptionRangedI64<MIN, MAX>
fn clone(&self) -> OptionRangedI64<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: i64, const MAX: i64> Deserialize<'de> for OptionRangedI64<MIN, MAX>
impl<'de, const MIN: i64, const MAX: i64> Deserialize<'de> for OptionRangedI64<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§#[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: i64, const MAX: i64> Distribution<OptionRangedI64<MIN, MAX>> for Standard
impl<const MIN: i64, const MAX: i64> Distribution<OptionRangedI64<MIN, MAX>> for Standard
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OptionRangedI64<MIN, MAX>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OptionRangedI64<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: i64, const MAX: i64> Eq for OptionRangedI64<MIN, MAX>
impl<const MIN: i64, const MAX: i64> Eq for OptionRangedI64<MIN, MAX>
#[doc(hidden)] fn assert_receiver_is_total_eq(&self)
Source§impl<const MIN: i64, const MAX: i64> From<Option<RangedI64<MIN, MAX>>> for OptionRangedI64<MIN, MAX>
impl<const MIN: i64, const MAX: i64> From<Option<RangedI64<MIN, MAX>>> for OptionRangedI64<MIN, MAX>
Source§impl<const MIN: i64, const MAX: i64> From<OptionRangedI64<MIN, MAX>> for Option<RangedI64<MIN, MAX>>
impl<const MIN: i64, const MAX: i64> From<OptionRangedI64<MIN, MAX>> for Option<RangedI64<MIN, MAX>>
Source§fn from(value: OptionRangedI64<MIN, MAX>) -> Self
fn from(value: OptionRangedI64<MIN, MAX>) -> Self
Source§impl<const MIN: i64, const MAX: i64> Ord for OptionRangedI64<MIN, MAX>
impl<const MIN: i64, const MAX: i64> Ord for OptionRangedI64<MIN, MAX>
Source§impl<const MIN_A: i64, const MAX_A: i64, const MIN_B: i64, const MAX_B: i64> PartialEq<OptionRangedI64<MIN_B, MAX_B>> for OptionRangedI64<MIN_A, MAX_A>
impl<const MIN_A: i64, const MAX_A: i64, const MIN_B: i64, const MAX_B: i64> PartialEq<OptionRangedI64<MIN_B, MAX_B>> for OptionRangedI64<MIN_A, MAX_A>
Source§fn eq(&self, other: &OptionRangedI64<MIN_B, MAX_B>) -> bool
fn eq(&self, other: &OptionRangedI64<MIN_B, MAX_B>) -> bool
self
and other
values to be equal, and is used by ==
.