pub struct UInt(/* private fields */);
Expand description
An integer limited to the range of non-negative integers that can be represented exactly by an f64.
Implementations§
Source§impl UInt
impl UInt
Sourcepub const MIN: UInt = _
pub const MIN: UInt = _
The smallest value that can be represented by this integer type.
§Examples
Basic usage:
assert_eq!(UInt::MIN, uint!(0));
Sourcepub const MAX: UInt = _
pub const MAX: UInt = _
The largest value that can be represented by this integer type.
§Examples
Basic usage:
assert_eq!(UInt::MAX, UInt::try_from(9_007_199_254_740_991u64).unwrap());
Sourcepub fn new(val: u64) -> Option<UInt>
pub fn new(val: u64) -> Option<UInt>
Try to create a UInt
from the provided u64
, returning None
if it is larger than
MAX_SAFE_UINT
.
This is the same as the TryFrom<u64>
implementation for UInt
, except that it returns
an Option
instead of a Result
.
§Examples
Basic usage:
assert_eq!(UInt::new(js_int::MAX_SAFE_UINT), Some(UInt::MAX));
assert_eq!(UInt::new(js_int::MAX_SAFE_UINT + 1), None);
Sourcepub fn new_wrapping(val: u64) -> UInt
pub fn new_wrapping(val: u64) -> UInt
Create a UInt
from the provided u64
, wrapping at MAX_SAFE_UINT
.
§Examples
Basic usage:
assert_eq!(UInt::new_wrapping(js_int::MAX_SAFE_UINT), UInt::MAX);
assert_eq!(UInt::new_wrapping(js_int::MAX_SAFE_UINT + 1), uint!(0));
Sourcepub fn new_saturating(val: u64) -> UInt
pub fn new_saturating(val: u64) -> UInt
Creates an UInt
from the given u64
capped at MAX_SAFE_UINT
.
§Examples
Basic usage:
assert_eq!(UInt::new_saturating(0), uint!(0));
assert_eq!(UInt::new_saturating(js_int::MAX_SAFE_UINT), UInt::MAX);
assert_eq!(UInt::new_saturating(js_int::MAX_SAFE_UINT + 1), UInt::MAX);
Sourcepub const fn min_value() -> UInt
👎Deprecated: Use UInt::MIN
instead.
pub const fn min_value() -> UInt
UInt::MIN
instead.Returns the smallest value that can be represented by this integer type.
§Examples
Basic usage:
assert_eq!(UInt::min_value(), uint!(0));
Sourcepub const fn max_value() -> UInt
👎Deprecated: Use UInt::MAX
instead.
pub const fn max_value() -> UInt
UInt::MAX
instead.Returns the largest value that can be represented by this integer type.
§Examples
Basic usage:
assert_eq!(UInt::max_value(), UInt::try_from(9_007_199_254_740_991u64).unwrap());
Sourcepub fn is_power_of_two(self) -> bool
pub fn is_power_of_two(self) -> bool
Returns true if and only if self == 2^k
for some k
.
§Examples
Basic usage:
assert!(uint!(16).is_power_of_two());
assert!(!uint!(10).is_power_of_two());
Sourcepub fn checked_next_power_of_two(self) -> Option<UInt>
pub fn checked_next_power_of_two(self) -> Option<UInt>
Returns the smallest power of two greater than or equal to n
. If the next power of two is
greater than the type’s maximum value, None
is returned, otherwise the power of two is
wrapped in Some
.
§Examples
Basic usage:
assert_eq!(uint!(2).checked_next_power_of_two(), Some(uint!(2)));
assert_eq!(uint!(3).checked_next_power_of_two(), Some(uint!(4)));
assert_eq!(UInt::MAX.checked_next_power_of_two(), None);
Sourcepub fn from_str_radix(src: &str, radix: u32) -> Result<UInt, ParseIntError>
pub fn from_str_radix(src: &str, radix: u32) -> Result<UInt, ParseIntError>
Converts a string slice in a given base to an integer.
The string is expected to be an optional +
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
This function panics if radix
is not in the range from 2 to 36.
§Examples
Basic usage:
assert_eq!(UInt::from_str_radix("A", 16), Ok(uint!(10)));
Sourcepub fn checked_add(self, rhs: UInt) -> Option<UInt>
pub fn checked_add(self, rhs: UInt) -> Option<UInt>
Checked integer addition. Computes self + rhs
, returning None
if overflow occurred.
assert_eq!(
(UInt::MAX - uint!(2)).checked_add(uint!(1)),
Some(UInt::MAX - uint!(1))
);
assert_eq!((UInt::MAX - uint!(2)).checked_add(uint!(3)), None);
Sourcepub fn checked_sub(self, rhs: UInt) -> Option<UInt>
pub fn checked_sub(self, rhs: UInt) -> Option<UInt>
Checked integer subtraction. Computes self - rhs
, returning None
if overflow occurred.
§Examples
Basic usage:
assert_eq!(uint!(1).checked_sub(uint!(1)), Some(uint!(0)));
assert_eq!(uint!(0).checked_sub(uint!(1)), None);
Sourcepub fn checked_mul(self, rhs: UInt) -> Option<UInt>
pub fn checked_mul(self, rhs: UInt) -> Option<UInt>
Checked integer multiplication. Computes self * rhs
, returning None
if overflow
occurred.
§Examples
Basic usage:
assert_eq!(uint!(5).checked_mul(uint!(1)), Some(uint!(5)));
assert_eq!(UInt::MAX.checked_mul(uint!(2)), None);
Sourcepub fn checked_div(self, rhs: UInt) -> Option<UInt>
pub fn checked_div(self, rhs: UInt) -> Option<UInt>
Checked integer division. Computes self / rhs
, returning None
if rhs == 0
.
§Examples
Basic usage:
assert_eq!(uint!(128).checked_div(uint!(2)), Some(uint!(64)));
assert_eq!(uint!(1).checked_div(uint!(0)), None);
Sourcepub fn checked_rem(self, rhs: UInt) -> Option<UInt>
pub fn checked_rem(self, rhs: UInt) -> Option<UInt>
Checked integer remainder. Computes self % rhs
, returning None
if rhs == 0
.
§Examples
Basic usage:
assert_eq!(uint!(5).checked_rem(uint!(2)), Some(uint!(1)));
assert_eq!(uint!(5).checked_rem(uint!(0)), None);
Sourcepub fn checked_neg(self) -> Option<UInt>
pub fn checked_neg(self) -> Option<UInt>
Checked negation. Computes -self
, returning None unless self == 0
.
Note that negating any positive integer will overflow.
§Examples
Basic usage:
assert_eq!(uint!(0).checked_neg(), Some(uint!(0)));
assert_eq!(uint!(1).checked_neg(), None);
Sourcepub fn checked_pow(self, exp: u32) -> Option<UInt>
pub fn checked_pow(self, exp: u32) -> Option<UInt>
Checked exponentiation. Computes self.pow(exp)
, returning None
if overflow or
underflow occurred.
§Examples
Basic usage:
assert_eq!(uint!(0).checked_pow(2), Some(uint!(0)));
assert_eq!(uint!(8).checked_pow(2), Some(uint!(64)));
assert_eq!(uint!(1_000_000_000u32).checked_pow(2), None);
assert_eq!(UInt::MAX.checked_pow(2), None);
Sourcepub fn saturating_add(self, rhs: UInt) -> UInt
pub fn saturating_add(self, rhs: UInt) -> UInt
Saturating integer addition. Computes self + rhs
, saturating at the numeric bounds
instead of overflowing.
§Examples
Basic usage:
assert_eq!(uint!(100).saturating_add(uint!(1)), uint!(101));
assert_eq!(UInt::MAX.saturating_add(uint!(1)), UInt::MAX);
Sourcepub fn saturating_sub(self, rhs: UInt) -> UInt
pub fn saturating_sub(self, rhs: UInt) -> UInt
Saturating integer subtraction. Computes self - rhs
, saturating at the numeric
bounds instead of underflowing.
§Examples
Basic usage:
assert_eq!(uint!(100).saturating_sub(uint!(1)), uint!(99));
assert_eq!(uint!(1).saturating_sub(uint!(2)), uint!(0));
Sourcepub fn saturating_mul(self, rhs: UInt) -> UInt
pub fn saturating_mul(self, rhs: UInt) -> UInt
Saturating integer multiplication. Computes self * rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(uint!(100).saturating_mul(uint!(2)), uint!(200));
assert_eq!(UInt::MAX.saturating_mul(uint!(2)), UInt::MAX);
assert_eq!(UInt::MAX.saturating_mul(UInt::MAX), UInt::MAX);
Sourcepub fn saturating_pow(self, exp: u32) -> UInt
pub fn saturating_pow(self, exp: u32) -> UInt
Saturating integer exponentiation. Computes self.pow(exp)
, saturating at the
numeric bounds instead of overflowing or underflowing.
§Examples
Basic usage:
assert_eq!(uint!(5).saturating_pow(2), uint!(25));
assert_eq!(UInt::MAX.saturating_pow(2), UInt::MAX);
Trait Implementations§
Source§impl AddAssign for UInt
impl AddAssign for UInt
Source§fn add_assign(&mut self, other: UInt)
fn add_assign(&mut self, other: UInt)
+=
operation. Read moreSource§impl<'de> Deserialize<'de> for UInt
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for UInt
serde
only.Source§fn deserialize<D>(
deserializer: D,
) -> Result<UInt, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<UInt, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl DivAssign for UInt
impl DivAssign for UInt
Source§fn div_assign(&mut self, other: UInt)
fn div_assign(&mut self, other: UInt)
/=
operation. Read moreSource§impl From<UInt> for CanonicalJsonValue
impl From<UInt> for CanonicalJsonValue
Source§fn from(value: UInt) -> CanonicalJsonValue
fn from(value: UInt) -> CanonicalJsonValue
Source§impl From<UInt> for RoomMemberCountIs
impl From<UInt> for RoomMemberCountIs
Source§fn from(x: UInt) -> RoomMemberCountIs
fn from(x: UInt) -> RoomMemberCountIs
Source§impl MulAssign for UInt
impl MulAssign for UInt
Source§fn mul_assign(&mut self, other: UInt)
fn mul_assign(&mut self, other: UInt)
*=
operation. Read moreSource§impl Ord for UInt
impl Ord for UInt
Source§impl PartialOrd for UInt
impl PartialOrd for UInt
Source§impl RangeBounds<UInt> for RoomMemberCountIs
impl RangeBounds<UInt> for RoomMemberCountIs
Source§impl RemAssign for UInt
impl RemAssign for UInt
Source§fn rem_assign(&mut self, other: UInt)
fn rem_assign(&mut self, other: UInt)
%=
operation. Read moreSource§impl Serialize for UInt
impl Serialize for UInt
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl SubAssign for UInt
impl SubAssign for UInt
Source§fn sub_assign(&mut self, other: UInt)
fn sub_assign(&mut self, other: UInt)
-=
operation. Read moreSource§impl TryFrom<UInt> for VoipVersionId
impl TryFrom<UInt> for VoipVersionId
impl Copy for UInt
impl Eq for UInt
impl StructuralPartialEq for UInt
Auto Trait Implementations§
impl Freeze for UInt
impl RefUnwindSafe for UInt
impl Send for UInt
impl Sync for UInt
impl Unpin for UInt
impl UnwindSafe for UInt
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§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more