pub struct Uint64(_);
Expand description
A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.
Examples
Use from
to create instances of this and u64
to get the value out:
let a = Uint64::from(42u64);
assert_eq!(a.u64(), 42);
let b = Uint64::from(70u32);
assert_eq!(b.u64(), 70);
Implementations§
source§impl Uint64
impl Uint64
pub const MAX: Uint64 = Self(u64::MAX)
pub const MIN: Uint64 = Self(u64::MIN)
sourcepub const fn new(value: u64) -> Uint64
pub const fn new(value: u64) -> Uint64
Creates a Uint64(value).
This method is less flexible than from
but can be called in a const context.
sourcepub const fn to_be_bytes(self) -> [u8; 8]
pub const fn to_be_bytes(self) -> [u8; 8]
Returns a copy of the number as big endian bytes.
sourcepub const fn to_le_bytes(self) -> [u8; 8]
pub const fn to_le_bytes(self) -> [u8; 8]
Returns a copy of the number as little endian bytes.
pub const fn is_zero(&self) -> bool
pub fn pow(self, exp: u32) -> Uint64
sourcepub fn multiply_ratio<A, B>(&self, numerator: A, denominator: B) -> Uint64where
A: Into<u64>,
B: Into<u64>,
pub fn multiply_ratio<A, B>(&self, numerator: A, denominator: B) -> Uint64where A: Into<u64>, B: Into<u64>,
Returns self * numerator / denominator
.
Due to the nature of the integer division involved, the result is always floored. E.g. 5 * 99/100 = 4.
sourcepub fn checked_multiply_ratio<A, B>(
&self,
numerator: A,
denominator: B
) -> Result<Uint64, CheckedMultiplyRatioError>where
A: Into<u64>,
B: Into<u64>,
pub fn checked_multiply_ratio<A, B>( &self, numerator: A, denominator: B ) -> Result<Uint64, CheckedMultiplyRatioError>where A: Into<u64>, B: Into<u64>,
Returns self * numerator / denominator
.
Due to the nature of the integer division involved, the result is always floored. E.g. 5 * 99/100 = 4.
pub fn checked_add(self, other: Uint64) -> Result<Uint64, OverflowError>
pub fn checked_sub(self, other: Uint64) -> Result<Uint64, OverflowError>
pub fn checked_mul(self, other: Uint64) -> Result<Uint64, OverflowError>
pub fn checked_pow(self, exp: u32) -> Result<Uint64, OverflowError>
pub fn checked_div(self, other: Uint64) -> Result<Uint64, DivideByZeroError>
pub fn checked_div_euclid( self, other: Uint64 ) -> Result<Uint64, DivideByZeroError>
pub fn checked_rem(self, other: Uint64) -> Result<Uint64, DivideByZeroError>
pub fn wrapping_add(self, other: Uint64) -> Uint64
pub fn wrapping_sub(self, other: Uint64) -> Uint64
pub fn wrapping_mul(self, other: Uint64) -> Uint64
pub fn wrapping_pow(self, other: u32) -> Uint64
pub fn saturating_add(self, other: Uint64) -> Uint64
pub fn saturating_sub(self, other: Uint64) -> Uint64
pub fn saturating_mul(self, other: Uint64) -> Uint64
pub fn saturating_pow(self, exp: u32) -> Uint64
pub const fn abs_diff(self, other: Uint64) -> Uint64
Trait Implementations§
source§impl<'a> AddAssign<&'a Uint64> for Uint64
impl<'a> AddAssign<&'a Uint64> for Uint64
source§fn add_assign(&mut self, rhs: &'a Uint64)
fn add_assign(&mut self, rhs: &'a Uint64)
+=
operation. Read moresource§impl AddAssign<Uint64> for Uint64
impl AddAssign<Uint64> for Uint64
source§fn add_assign(&mut self, rhs: Uint64)
fn add_assign(&mut self, rhs: Uint64)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for Uint64
impl<'de> Deserialize<'de> for Uint64
source§fn deserialize<D>(
deserializer: D
) -> Result<Uint64, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Uint64, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
Deserialized from an integer string using base 10
source§impl<'a> DivAssign<&'a Uint64> for Uint64
impl<'a> DivAssign<&'a Uint64> for Uint64
source§fn div_assign(&mut self, rhs: &'a Uint64)
fn div_assign(&mut self, rhs: &'a Uint64)
/=
operation. Read moresource§impl DivAssign<Uint64> for Uint64
impl DivAssign<Uint64> for Uint64
source§fn div_assign(&mut self, rhs: Uint64)
fn div_assign(&mut self, rhs: Uint64)
/=
operation. Read moresource§impl FadromaDeserialize for Uint64
impl FadromaDeserialize for Uint64
source§fn from_bytes<'a>(de: &mut Deserializer<'a>) -> Result<Self>
fn from_bytes<'a>(de: &mut Deserializer<'a>) -> Result<Self>
Deserializer
.source§impl FadromaSerialize for Uint64
impl FadromaSerialize for Uint64
source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
source§fn to_bytes(&self, ser: &mut Serializer) -> Result<()>
fn to_bytes(&self, ser: &mut Serializer) -> Result<()>
Serializer
.source§impl JsonSchema for Uint64
impl JsonSchema for Uint64
source§fn schema_name() -> String
fn schema_name() -> String
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl MulAssign<&Uint64> for Uint64
impl MulAssign<&Uint64> for Uint64
source§fn mul_assign(&mut self, other: &Uint64)
fn mul_assign(&mut self, other: &Uint64)
*=
operation. Read moresource§impl MulAssign<Uint64> for Uint64
impl MulAssign<Uint64> for Uint64
source§fn mul_assign(&mut self, rhs: Uint64)
fn mul_assign(&mut self, rhs: Uint64)
*=
operation. Read moresource§impl Ord for Uint64
impl Ord for Uint64
source§impl PartialEq<&Uint64> for Uint64
impl PartialEq<&Uint64> for Uint64
source§impl PartialEq<Uint64> for &Uint64
impl PartialEq<Uint64> for &Uint64
source§impl PartialEq<Uint64> for Uint64
impl PartialEq<Uint64> for Uint64
source§impl PartialOrd<Uint64> for Uint64
impl PartialOrd<Uint64> for Uint64
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl RemAssign<&Uint64> for Uint64
impl RemAssign<&Uint64> for Uint64
source§fn rem_assign(&mut self, other: &Uint64)
fn rem_assign(&mut self, other: &Uint64)
%=
operation. Read moresource§impl RemAssign<Uint64> for Uint64
impl RemAssign<Uint64> for Uint64
source§fn rem_assign(&mut self, rhs: Uint64)
fn rem_assign(&mut self, rhs: Uint64)
%=
operation. Read moresource§impl Serialize for Uint64
impl Serialize for Uint64
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,
Serializes as an integer string using base 10
source§impl<'a> ShrAssign<&'a u32> for Uint64
impl<'a> ShrAssign<&'a u32> for Uint64
source§fn shr_assign(&mut self, rhs: &'a u32)
fn shr_assign(&mut self, rhs: &'a u32)
>>=
operation. Read moresource§impl ShrAssign<u32> for Uint64
impl ShrAssign<u32> for Uint64
source§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>=
operation. Read moresource§impl SubAssign<&Uint64> for Uint64
impl SubAssign<&Uint64> for Uint64
source§fn sub_assign(&mut self, other: &Uint64)
fn sub_assign(&mut self, other: &Uint64)
-=
operation. Read moresource§impl SubAssign<Uint64> for Uint64
impl SubAssign<Uint64> for Uint64
source§fn sub_assign(&mut self, rhs: Uint64)
fn sub_assign(&mut self, rhs: Uint64)
-=
operation. Read more