Struct deranged::RangedI128
source · pub struct RangedI128<const MIN: i128, const MAX: i128>(/* private fields */);
Expand description
An i128
that is known to be in the range MIN..=MAX
.
Implementations§
source§impl RangedI128<0, 0>
impl RangedI128<0, 0>
pub const fn exact<const VALUE: i128>() -> RangedI128<VALUE, VALUE>
source§impl<const MIN: i128, const MAX: i128> RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> RangedI128<MIN, MAX>
sourcepub const unsafe fn new_unchecked(value: i128) -> Self
pub const unsafe fn new_unchecked(value: i128) -> Self
Creates a ranged integer without checking the value.
§Safety
The value must be within the range MIN..=MAX
.
sourcepub const fn new(value: i128) -> Option<Self>
pub const fn new(value: i128) -> Option<Self>
Creates a ranged integer if the given value is in the range MIN..=MAX
.
sourcepub const fn new_static<const VALUE: i128>() -> Self
pub const fn new_static<const VALUE: i128>() -> Self
Creates a ranged integer with a statically known value. Fails to compile if the value is not in range.
sourcepub const fn new_saturating(value: i128) -> Self
pub const fn new_saturating(value: i128) -> Self
Creates a ranged integer with the given value, saturating if it is out of range.
sourcepub const fn expand<const NEW_MIN: i128, const NEW_MAX: i128>(
self,
) -> RangedI128<NEW_MIN, NEW_MAX>
pub const fn expand<const NEW_MIN: i128, const NEW_MAX: i128>( self, ) -> RangedI128<NEW_MIN, NEW_MAX>
Expand the range that the value may be in. Fails to compile if the new range is not a superset of the current range.
sourcepub const fn narrow<const NEW_MIN: i128, const NEW_MAX: i128>(
self,
) -> Option<RangedI128<NEW_MIN, NEW_MAX>>
pub const fn narrow<const NEW_MIN: i128, const NEW_MAX: i128>( self, ) -> Option<RangedI128<NEW_MIN, NEW_MAX>>
Attempt to narrow the range that the value may be in. Returns None
if the value
is outside the new range. Fails to compile if the new range is not a subset of
the current range.
sourcepub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>
Converts a string slice in a given base to an integer.
The string is expected to be an optional +
or -
sign followed by digits. Leading
and trailing whitespace represent an error. Digits are a subset of these characters,
depending on radix
:
0-9
a-z
A-Z
§Panics
Panics if radix
is not in the range 2..=36
.
§Examples
Basic usage:
assert_eq!(RangedI128::<5, 10>::from_str_radix("A", 16), Ok(RangedI128::new_static::<10>()));
sourcepub const fn checked_add(self, rhs: i128) -> Option<Self>
pub const fn checked_add(self, rhs: i128) -> Option<Self>
Checked integer addition. Computes self + rhs
, returning None
if the resulting
value is out of range.
sourcepub const unsafe fn unchecked_add(self, rhs: i128) -> Self
pub const unsafe fn unchecked_add(self, rhs: i128) -> Self
Unchecked integer addition. Computes self + rhs
, assuming that the result is in
range.
§Safety
The result of self + rhs
must be in the range MIN..=MAX
.
sourcepub const fn checked_sub(self, rhs: i128) -> Option<Self>
pub const fn checked_sub(self, rhs: i128) -> Option<Self>
Checked integer addition. Computes self - rhs
, returning None
if the resulting
value is out of range.
sourcepub const unsafe fn unchecked_sub(self, rhs: i128) -> Self
pub const unsafe fn unchecked_sub(self, rhs: i128) -> Self
Unchecked integer subtraction. Computes self - rhs
, assuming that the result is in
range.
§Safety
The result of self - rhs
must be in the range MIN..=MAX
.
sourcepub const fn checked_mul(self, rhs: i128) -> Option<Self>
pub const fn checked_mul(self, rhs: i128) -> Option<Self>
Checked integer addition. Computes self * rhs
, returning None
if the resulting
value is out of range.
sourcepub const unsafe fn unchecked_mul(self, rhs: i128) -> Self
pub const unsafe fn unchecked_mul(self, rhs: i128) -> Self
Unchecked integer multiplication. Computes self * rhs
, assuming that the result is
in range.
§Safety
The result of self * rhs
must be in the range MIN..=MAX
.
sourcepub const fn checked_div(self, rhs: i128) -> Option<Self>
pub const fn checked_div(self, rhs: i128) -> Option<Self>
Checked integer addition. Computes self / rhs
, returning None
if rhs == 0
or
if the resulting value is out of range.
sourcepub const unsafe fn unchecked_div(self, rhs: i128) -> Self
pub const unsafe fn unchecked_div(self, rhs: i128) -> Self
Unchecked integer division. Computes self / rhs
, assuming that rhs != 0
and that
the result is in range.
§Safety
self
must not be zero and the result of self / rhs
must be in the range
MIN..=MAX
.
sourcepub const fn checked_div_euclid(self, rhs: i128) -> Option<Self>
pub const fn checked_div_euclid(self, rhs: i128) -> Option<Self>
Checked Euclidean division. Computes self.div_euclid(rhs)
, returning None
if
rhs == 0
or if the resulting value is out of range.
sourcepub const unsafe fn unchecked_div_euclid(self, rhs: i128) -> Self
pub const unsafe fn unchecked_div_euclid(self, rhs: i128) -> Self
Unchecked Euclidean division. Computes self.div_euclid(rhs)
, assuming that
rhs != 0
and that the result is in range.
§Safety
self
must not be zero and the result of self.div_euclid(rhs)
must be in the
range MIN..=MAX
.
sourcepub const fn checked_rem(self, rhs: i128) -> Option<Self>
pub const fn checked_rem(self, rhs: i128) -> Option<Self>
Checked integer remainder. Computes self % rhs
, returning None
if rhs == 0
or
if the resulting value is out of range.
sourcepub const unsafe fn unchecked_rem(self, rhs: i128) -> Self
pub const unsafe fn unchecked_rem(self, rhs: i128) -> Self
Unchecked remainder. Computes self % rhs
, assuming that rhs != 0
and that the
result is in range.
§Safety
self
must not be zero and the result of self % rhs
must be in the range
MIN..=MAX
.
sourcepub const fn checked_rem_euclid(self, rhs: i128) -> Option<Self>
pub const fn checked_rem_euclid(self, rhs: i128) -> Option<Self>
Checked Euclidean remainder. Computes self.rem_euclid(rhs)
, returning None
if
rhs == 0
or if the resulting value is out of range.
sourcepub const unsafe fn unchecked_rem_euclid(self, rhs: i128) -> Self
pub const unsafe fn unchecked_rem_euclid(self, rhs: i128) -> Self
Unchecked Euclidean remainder. Computes self.rem_euclid(rhs)
, assuming that
rhs != 0
and that the result is in range.
§Safety
self
must not be zero and the result of self.rem_euclid(rhs)
must be in the
range MIN..=MAX
.
sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self
, returning None
if the resulting value is out
of range.
sourcepub const unsafe fn unchecked_neg(self) -> Self
pub const unsafe fn unchecked_neg(self) -> Self
Unchecked negation. Computes -self
, assuming that -self
is in range.
§Safety
The result of -self
must be in the range MIN..=MAX
.
sourcepub const fn neg(self) -> Self
pub const fn neg(self) -> Self
Negation. Computes self.neg()
, failing to compile if the result is not
guaranteed to be in range.
sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Checked shift left. Computes self << rhs
, returning None
if the resulting value
is out of range.
sourcepub const unsafe fn unchecked_shl(self, rhs: u32) -> Self
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self
Unchecked shift left. Computes self << rhs
, assuming that the result is in range.
§Safety
The result of self << rhs
must be in the range MIN..=MAX
.
sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Checked shift right. Computes self >> rhs
, returning None
if
the resulting value is out of range.
sourcepub const unsafe fn unchecked_shr(self, rhs: u32) -> Self
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self
Unchecked shift right. Computes self >> rhs
, assuming that the result is in range.
§Safety
The result of self >> rhs
must be in the range MIN..=MAX
.
sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
Checked absolute value. Computes self.abs()
, returning None
if the resulting
value is out of range.
sourcepub const unsafe fn unchecked_abs(self) -> Self
pub const unsafe fn unchecked_abs(self) -> Self
Unchecked absolute value. Computes self.abs()
, assuming that the result is in
range.
§Safety
The result of self.abs()
must be in the range MIN..=MAX
.
sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Absolute value. Computes self.abs()
, failing to compile if the result is not
guaranteed to be in range.
sourcepub const fn checked_pow(self, exp: u32) -> Option<Self>
pub const fn checked_pow(self, exp: u32) -> Option<Self>
Checked exponentiation. Computes self.pow(exp)
, returning None
if the resulting
value is out of range.
sourcepub const unsafe fn unchecked_pow(self, exp: u32) -> Self
pub const unsafe fn unchecked_pow(self, exp: u32) -> Self
Unchecked exponentiation. Computes self.pow(exp)
, assuming that the result is in
range.
§Safety
The result of self.pow(exp)
must be in the range MIN..=MAX
.
sourcepub const fn saturating_add(self, rhs: i128) -> Self
pub const fn saturating_add(self, rhs: i128) -> Self
Saturating integer addition. Computes self + rhs
, saturating at the numeric
bounds.
sourcepub const fn saturating_sub(self, rhs: i128) -> Self
pub const fn saturating_sub(self, rhs: i128) -> Self
Saturating integer subtraction. Computes self - rhs
, saturating at the numeric
bounds.
sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating integer negation. Computes self - rhs
, saturating at the numeric
bounds.
sourcepub const fn saturating_abs(self) -> Self
pub const fn saturating_abs(self) -> Self
Saturating absolute value. Computes self.abs()
, saturating at the numeric bounds.
sourcepub const fn saturating_mul(self, rhs: i128) -> Self
pub const fn saturating_mul(self, rhs: i128) -> Self
Saturating integer multiplication. Computes self * rhs
, saturating at the numeric
bounds.
sourcepub const fn saturating_pow(self, exp: u32) -> Self
pub const fn saturating_pow(self, exp: u32) -> Self
Saturating integer exponentiation. Computes self.pow(exp)
, saturating at the
numeric bounds.
sourcepub const fn wrapping_add(self, rhs: i128) -> Self
pub const fn wrapping_add(self, rhs: i128) -> Self
Wrapping integer addition. Computes self + rhs
, wrapping around the numeric
bounds.
sourcepub const fn wrapping_sub(self, rhs: i128) -> Self
pub const fn wrapping_sub(self, rhs: i128) -> Self
Wrapping integer subtraction. Computes self - rhs
, wrapping around the numeric
bounds.
Trait Implementations§
source§impl<const MIN: i128, const MAX: i128> Clone for RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Clone for RangedI128<MIN, MAX>
source§fn clone(&self) -> RangedI128<MIN, MAX>
fn clone(&self) -> RangedI128<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 RangedI128<MIN, MAX>
impl<'de, const MIN: i128, const MAX: i128> Deserialize<'de> for RangedI128<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: i128, const MAX: i128> Distribution<RangedI128<MIN, MAX>> for Standard
impl<const MIN: i128, const MAX: i128> Distribution<RangedI128<MIN, MAX>> for Standard
source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> RangedI128<MIN, MAX>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> RangedI128<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> Eq for RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Eq for RangedI128<MIN, MAX>
#[doc(hidden)] fn assert_receiver_is_total_eq(&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> From<RangedI128<MIN, MAX>> for i128
impl<const MIN: i128, const MAX: i128> From<RangedI128<MIN, MAX>> for i128
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 RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Ord for RangedI128<MIN, MAX>
source§fn cmp(&self, other: &RangedI128<MIN, MAX>) -> Ordering
fn cmp(&self, other: &RangedI128<MIN, MAX>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<const MIN_A: i128, const MAX_A: i128, const MIN_B: i128, const MAX_B: i128> PartialEq<RangedI128<MIN_B, MAX_B>> for RangedI128<MIN_A, MAX_A>
impl<const MIN_A: i128, const MAX_A: i128, const MIN_B: i128, const MAX_B: i128> PartialEq<RangedI128<MIN_B, MAX_B>> for RangedI128<MIN_A, MAX_A>
source§impl<const MIN_A: i128, const MAX_A: i128, const MIN_B: i128, const MAX_B: i128> PartialOrd<RangedI128<MIN_B, MAX_B>> for RangedI128<MIN_A, MAX_A>
impl<const MIN_A: i128, const MAX_A: i128, const MIN_B: i128, const MAX_B: i128> PartialOrd<RangedI128<MIN_B, MAX_B>> for RangedI128<MIN_A, MAX_A>
source§impl<const MIN: i128, const MAX: i128> SmartDisplay for RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> SmartDisplay for RangedI128<MIN, MAX>
source§fn metadata(&self, f: FormatterOptions) -> Metadata<'_, Self>
fn metadata(&self, f: FormatterOptions) -> Metadata<'_, Self>
impl<const MIN: i128, const MAX: i128> Copy for RangedI128<MIN, MAX>
Auto Trait Implementations§
impl<const MIN: i128, const MAX: i128> Freeze for RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> RefUnwindSafe for RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Send for RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Sync for RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> Unpin for RangedI128<MIN, MAX>
impl<const MIN: i128, const MAX: i128> UnwindSafe for RangedI128<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
)