pub struct OptionRangedI128<const MIN: i128, const MAX: i128>(/* private fields */);
Expand description
An optional RangedI128
; similar to Option<RangedI128>
with better optimization.
If MIN
is i128::MIN
and MAX
is i128::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 OptionRangedI128::get
.
Implementations§
Source§impl<const MIN: i128, const MAX: i128> OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> OptionRangedI128<MIN, MAX>
Sourcepub const fn Some(value: RangedI128<MIN, MAX>) -> Self
pub const fn Some(value: RangedI128<MIN, MAX>) -> Self
Creates an optional ranged value that is present.
Sourcepub const fn get(self) -> Option<RangedI128<MIN, MAX>>
pub const fn get(self) -> Option<RangedI128<MIN, MAX>>
Returns the value as the standard library’s Option
type.
Sourcepub const unsafe fn some_unchecked(value: i128) -> Self
pub const unsafe fn some_unchecked(value: i128) -> 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<i128>
pub const fn get_primitive(self) -> Option<i128>
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 OptionRangedI128::get_primitive_without_hint
.
Sourcepub const fn get_primitive_without_hint(self) -> Option<i128>
pub const fn get_primitive_without_hint(self) -> Option<i128>
Obtain the value of the struct as an Option
of the primitive type.
The returned value is identical to OptionRangedI128::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: i128, const MAX: i128> Arbitrary for OptionRangedI128<MIN, MAX>
Available on crate feature quickcheck
only.
impl<const MIN: i128, const MAX: i128> Arbitrary for OptionRangedI128<MIN, MAX>
quickcheck
only.Source§impl<const MIN: i128, const MAX: i128> Clone for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Clone for OptionRangedI128<MIN, MAX>
Source§fn clone(&self) -> OptionRangedI128<MIN, MAX>
fn clone(&self) -> OptionRangedI128<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: i128, const MAX: i128> Deserialize<'de> for OptionRangedI128<MIN, MAX>
Available on crate feature serde
only.
impl<'de, const MIN: i128, const MAX: i128> Deserialize<'de> for OptionRangedI128<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§impl<const MIN: i128, const MAX: i128> Distribution<OptionRangedI128<MIN, MAX>> for Standard
Available on crate feature rand08
only.
impl<const MIN: i128, const MAX: i128> Distribution<OptionRangedI128<MIN, MAX>> for Standard
rand08
only.Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OptionRangedI128<MIN, MAX>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OptionRangedI128<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: i128, const MAX: i128> From<Option<RangedI128<MIN, MAX>>> for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> From<Option<RangedI128<MIN, MAX>>> for OptionRangedI128<MIN, MAX>
Source§fn from(value: Option<RangedI128<MIN, MAX>>) -> Self
fn from(value: Option<RangedI128<MIN, MAX>>) -> Self
Source§impl<const MIN: i128, const MAX: i128> From<OptionRangedI128<MIN, MAX>> for Option<RangedI128<MIN, MAX>>
impl<const MIN: i128, const MAX: i128> From<OptionRangedI128<MIN, MAX>> for Option<RangedI128<MIN, MAX>>
Source§fn from(value: OptionRangedI128<MIN, MAX>) -> Self
fn from(value: OptionRangedI128<MIN, MAX>) -> Self
Source§impl<const MIN: i128, const MAX: i128> From<RangedI128<MIN, MAX>> for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> From<RangedI128<MIN, MAX>> for OptionRangedI128<MIN, MAX>
Source§fn from(value: RangedI128<MIN, MAX>) -> Self
fn from(value: RangedI128<MIN, MAX>) -> Self
Source§impl<const MIN: i128, const MAX: i128> Ord for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Ord for OptionRangedI128<MIN, MAX>
Source§impl<const MIN_A: i128, const MAX_A: i128, const MIN_B: i128, const MAX_B: i128> PartialEq<OptionRangedI128<MIN_B, MAX_B>> for OptionRangedI128<MIN_A, MAX_A>
impl<const MIN_A: i128, const MAX_A: i128, const MIN_B: i128, const MAX_B: i128> PartialEq<OptionRangedI128<MIN_B, MAX_B>> for OptionRangedI128<MIN_A, MAX_A>
Source§fn eq(&self, other: &OptionRangedI128<MIN_B, MAX_B>) -> bool
fn eq(&self, other: &OptionRangedI128<MIN_B, MAX_B>) -> bool
self
and other
values to be equal, and is used by ==
.Source§impl<const MIN_A: i128, const MAX_A: i128, const MIN_B: i128, const MAX_B: i128> PartialOrd<OptionRangedI128<MIN_B, MAX_B>> for OptionRangedI128<MIN_A, MAX_A>
impl<const MIN_A: i128, const MAX_A: i128, const MIN_B: i128, const MAX_B: i128> PartialOrd<OptionRangedI128<MIN_B, MAX_B>> for OptionRangedI128<MIN_A, MAX_A>
Source§impl<const MIN: i128, const MAX: i128> Serialize for OptionRangedI128<MIN, MAX>
Available on crate feature serde
only.
impl<const MIN: i128, const MAX: i128> Serialize for OptionRangedI128<MIN, MAX>
serde
only.