Struct deranged::OptionRangedI128
source · pub struct OptionRangedI128<const MIN: i128, const MAX: i128>(/* private fields */);
Expand description
A RangedI128
that is optional. Equivalent to Option<RangedI128>
with niche value 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.
source§impl<const MIN: i128, const MAX: i128> OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> OptionRangedI128<MIN, MAX>
Trait Implementations§
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<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>
impl<const MIN: i128, const MAX: i128> Copy for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Eq for OptionRangedI128<MIN, MAX>
Auto Trait Implementations§
impl<const MIN: i128, const MAX: i128> Freeze for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> RefUnwindSafe for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Send for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Sync for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Unpin for OptionRangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> UnwindSafe for OptionRangedI128<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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)