Struct levana_perpswap_cosmos::prelude::Uint64
pub struct Uint64(/* private fields */);
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§
§impl Uint64
impl Uint64
pub const MAX: Uint64 = _
pub const MIN: Uint64 = _
pub 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.
pub 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.
pub 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 const fn pow(self, exp: u32) -> Uint64
pub fn ilog2(self) -> u32
pub fn ilog2(self) -> u32
Returns the base 2 logarithm of the number, rounded down.
§Panics
This function will panic if self
is zero.
pub fn multiply_ratio<A, B>(&self, numerator: A, denominator: B) -> Uint64
pub fn multiply_ratio<A, B>(&self, numerator: A, denominator: B) -> Uint64
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_multiply_ratio<A, B>(
&self,
numerator: A,
denominator: B,
) -> Result<Uint64, CheckedMultiplyRatioError>
pub fn checked_multiply_ratio<A, B>( &self, numerator: A, denominator: B, ) -> Result<Uint64, CheckedMultiplyRatioError>
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 full_mul(self, rhs: impl Into<Uint64>) -> Uint128
pub fn full_mul(self, rhs: impl Into<Uint64>) -> Uint128
Multiplies two Uint64
/u64
values without overflow, producing an
[Uint128
].
§Examples
use cosmwasm_std::Uint64;
let a = Uint64::MAX;
let result = a.full_mul(2u32);
assert_eq!(result.to_string(), "36893488147419103230");
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 checked_shr(self, other: u32) -> Result<Uint64, OverflowError>
pub fn checked_shl(self, other: u32) -> Result<Uint64, OverflowError>
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 strict_add(self, rhs: Uint64) -> Uint64
pub const fn strict_add(self, rhs: Uint64) -> Uint64
Strict integer addition. Computes self + rhs
, panicking if overflow occurred.
This is the same as Uint64::add
but const.
pub const fn strict_sub(self, other: Uint64) -> Uint64
pub const fn strict_sub(self, other: Uint64) -> Uint64
Strict integer subtraction. Computes self - rhs
, panicking if overflow occurred.
This is the same as Uint64::sub
but const.
pub const fn abs_diff(self, other: Uint64) -> Uint64
§impl Uint64
impl Uint64
pub fn checked_mul_floor<F, T>(
self,
rhs: F,
) -> Result<Uint64, CheckedMultiplyFractionError>
pub fn checked_mul_floor<F, T>( self, rhs: F, ) -> Result<Uint64, CheckedMultiplyFractionError>
Multiply self
with a struct implementing [Fraction
] (e.g. [crate::Decimal
]).
Result is rounded down.
§Examples
use cosmwasm_std::Uint128;
let fraction = (8u128, 21u128);
let res = Uint128::new(123456).checked_mul_floor(fraction).unwrap();
assert_eq!(Uint128::new(47030), res); // 47030.8571 rounds down
pub fn checked_mul_ceil<F, T>(
self,
rhs: F,
) -> Result<Uint64, CheckedMultiplyFractionError>
pub fn checked_mul_ceil<F, T>( self, rhs: F, ) -> Result<Uint64, CheckedMultiplyFractionError>
Multiply self
with a struct implementing [Fraction
] (e.g. [crate::Decimal
]).
Result is rounded up.
§Examples
use cosmwasm_std::Uint128;
let fraction = (8u128, 21u128);
let res = Uint128::new(123456).checked_mul_ceil(fraction).unwrap();
assert_eq!(Uint128::new(47031), res); // 47030.8571 rounds up
pub fn checked_div_floor<F, T>(
self,
rhs: F,
) -> Result<Uint64, CheckedMultiplyFractionError>
pub fn checked_div_floor<F, T>( self, rhs: F, ) -> Result<Uint64, CheckedMultiplyFractionError>
Divide self
with a struct implementing [Fraction
] (e.g. [crate::Decimal
]).
Result is rounded down.
§Examples
use cosmwasm_std::Uint128;
let fraction = (4u128, 5u128);
let res = Uint128::new(789).checked_div_floor(fraction).unwrap();
assert_eq!(Uint128::new(986), res); // 986.25 rounds down
pub fn checked_div_ceil<F, T>(
self,
rhs: F,
) -> Result<Uint64, CheckedMultiplyFractionError>
pub fn checked_div_ceil<F, T>( self, rhs: F, ) -> Result<Uint64, CheckedMultiplyFractionError>
Divide self
with a struct implementing [Fraction
] (e.g. [crate::Decimal
]).
Result is rounded up.
§Examples
use cosmwasm_std::Uint128;
let fraction = (4u128, 5u128);
let res = Uint128::new(789).checked_div_ceil(fraction).unwrap();
assert_eq!(Uint128::new(987), res); // 986.25 rounds up
Trait Implementations§
§impl<'a> AddAssign<&'a Uint64> for Uint64
impl<'a> AddAssign<&'a Uint64> for Uint64
§fn add_assign(&mut self, rhs: &'a Uint64)
fn add_assign(&mut self, rhs: &'a Uint64)
+=
operation. Read more§impl AddAssign for Uint64
impl AddAssign for Uint64
§fn add_assign(&mut self, rhs: Uint64)
fn add_assign(&mut self, rhs: Uint64)
+=
operation. Read more§impl<'de> Deserialize<'de> for Uint64
impl<'de> Deserialize<'de> for Uint64
§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
§impl<'a> DivAssign<&'a Uint64> for Uint64
impl<'a> DivAssign<&'a Uint64> for Uint64
§fn div_assign(&mut self, rhs: &'a Uint64)
fn div_assign(&mut self, rhs: &'a Uint64)
/=
operation. Read more§impl DivAssign for Uint64
impl DivAssign for Uint64
§fn div_assign(&mut self, rhs: Uint64)
fn div_assign(&mut self, rhs: Uint64)
/=
operation. Read more§impl JsonSchema for Uint64
impl JsonSchema for Uint64
§fn schema_name() -> String
fn schema_name() -> String
§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read more§impl MulAssign<&Uint64> for Uint64
impl MulAssign<&Uint64> for Uint64
§fn mul_assign(&mut self, other: &Uint64)
fn mul_assign(&mut self, other: &Uint64)
*=
operation. Read more§impl MulAssign for Uint64
impl MulAssign for Uint64
§fn mul_assign(&mut self, rhs: Uint64)
fn mul_assign(&mut self, rhs: Uint64)
*=
operation. Read more§impl Ord for Uint64
impl Ord for Uint64
§impl PartialOrd for Uint64
impl PartialOrd for Uint64
§fn partial_cmp(&self, other: &Uint64) -> Option<Ordering>
fn partial_cmp(&self, other: &Uint64) -> Option<Ordering>
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 more§impl RemAssign<&Uint64> for Uint64
impl RemAssign<&Uint64> for Uint64
§fn rem_assign(&mut self, other: &Uint64)
fn rem_assign(&mut self, other: &Uint64)
%=
operation. Read more§impl RemAssign for Uint64
impl RemAssign for Uint64
§fn rem_assign(&mut self, rhs: Uint64)
fn rem_assign(&mut self, rhs: Uint64)
%=
operation. Read more§impl Serialize for Uint64
impl Serialize for Uint64
§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
§impl<'a> ShlAssign<&'a u32> for Uint64
impl<'a> ShlAssign<&'a u32> for Uint64
§fn shl_assign(&mut self, rhs: &'a u32)
fn shl_assign(&mut self, rhs: &'a u32)
<<=
operation. Read more§impl ShlAssign<u32> for Uint64
impl ShlAssign<u32> for Uint64
§fn shl_assign(&mut self, rhs: u32)
fn shl_assign(&mut self, rhs: u32)
<<=
operation. Read more§impl<'a> ShrAssign<&'a u32> for Uint64
impl<'a> ShrAssign<&'a u32> for Uint64
§fn shr_assign(&mut self, rhs: &'a u32)
fn shr_assign(&mut self, rhs: &'a u32)
>>=
operation. Read more§impl ShrAssign<u32> for Uint64
impl ShrAssign<u32> for Uint64
§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>=
operation. Read more§impl SubAssign<&Uint64> for Uint64
impl SubAssign<&Uint64> for Uint64
§fn sub_assign(&mut self, other: &Uint64)
fn sub_assign(&mut self, other: &Uint64)
-=
operation. Read more§impl SubAssign for Uint64
impl SubAssign for Uint64
§fn sub_assign(&mut self, rhs: Uint64)
fn sub_assign(&mut self, rhs: Uint64)
-=
operation. Read moreimpl Copy for Uint64
impl Eq for Uint64
impl StructuralPartialEq for Uint64
Auto Trait Implementations§
impl Freeze for Uint64
impl RefUnwindSafe for Uint64
impl Send for Uint64
impl Sync for Uint64
impl Unpin for Uint64
impl UnwindSafe for Uint64
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moresource§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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
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