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

pub const MAX: Uint64 = _

pub const MIN: 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 zero() -> Uint64

Creates a Uint64(0)

pub const fn one() -> Uint64

Creates a Uint64(1)

pub const fn u64(&self) -> u64

Returns a copy of the internal data

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]

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 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.

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 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

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

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

pub fn checked_mul_floor<F, T>( self, rhs: F ) -> Result<Uint64, CheckedMultiplyFractionError>where F: Fraction<T>, T: Into<Uint64>,

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 mul_floor<F, T>(self, rhs: F) -> Uint64where F: Fraction<T>, T: Into<Uint64>,

Same operation as checked_mul_floor except unwrapped

pub fn checked_mul_ceil<F, T>( self, rhs: F ) -> Result<Uint64, CheckedMultiplyFractionError>where F: Fraction<T>, T: Into<Uint64>,

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 mul_ceil<F, T>(self, rhs: F) -> Uint64where F: Fraction<T>, T: Into<Uint64>,

Same operation as checked_mul_ceil except unwrapped

pub fn checked_div_floor<F, T>( self, rhs: F ) -> Result<Uint64, CheckedMultiplyFractionError>where F: Fraction<T>, T: Into<Uint64>, Uint64: Sized,

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 div_floor<F, T>(self, rhs: F) -> Uint64where F: Fraction<T>, T: Into<Uint64>, Uint64: Sized,

Same operation as checked_div_floor except unwrapped

pub fn checked_div_ceil<F, T>( self, rhs: F ) -> Result<Uint64, CheckedMultiplyFractionError>where F: Fraction<T>, T: Into<Uint64>, Uint64: Sized,

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

pub fn div_ceil<F, T>(self, rhs: F) -> Uint64where F: Fraction<T>, T: Into<Uint64>, Uint64: Sized,

Same operation as checked_div_ceil except unwrapped

Trait Implementations§

§

impl Add<&Uint64> for &Uint64

§

type Output = <Uint64 as Add>::Output

The resulting type after applying the + operator.
§

fn add(self, other: &Uint64) -> <Uint64 as Add>::Output

Performs the + operation. Read more
§

impl Add<&Uint64> for Uint64

§

type Output = <Uint64 as Add>::Output

The resulting type after applying the + operator.
§

fn add(self, other: &Uint64) -> <Uint64 as Add>::Output

Performs the + operation. Read more
§

impl<'a> Add<Uint64> for &'a Uint64

§

type Output = <Uint64 as Add>::Output

The resulting type after applying the + operator.
§

fn add(self, other: Uint64) -> <Uint64 as Add>::Output

Performs the + operation. Read more
§

impl Add for Uint64

§

type Output = Uint64

The resulting type after applying the + operator.
§

fn add(self, rhs: Uint64) -> Uint64

Performs the + operation. Read more
§

impl<'a> AddAssign<&'a Uint64> for Uint64

§

fn add_assign(&mut self, rhs: &'a Uint64)

Performs the += operation. Read more
§

impl AddAssign for Uint64

§

fn add_assign(&mut self, rhs: Uint64)

Performs the += operation. Read more
§

impl Clone for Uint64

§

fn clone(&self) -> Uint64

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Uint64

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Uint64

§

fn default() -> Uint64

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for Uint64

§

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 Display for Uint64

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'a> Div<&'a Uint64> for Uint64

§

type Output = Uint64

The resulting type after applying the / operator.
§

fn div(self, rhs: &'a Uint64) -> <Uint64 as Div<&'a Uint64>>::Output

Performs the / operation. Read more
§

impl Div for Uint64

§

type Output = Uint64

The resulting type after applying the / operator.
§

fn div(self, rhs: Uint64) -> <Uint64 as Div>::Output

Performs the / operation. Read more
§

impl<'a> DivAssign<&'a Uint64> for Uint64

§

fn div_assign(&mut self, rhs: &'a Uint64)

Performs the /= operation. Read more
§

impl DivAssign for Uint64

§

fn div_assign(&mut self, rhs: Uint64)

Performs the /= operation. Read more
§

impl From<u16> for Uint64

§

fn from(val: u16) -> Uint64

Converts to this type from the input type.
§

impl From<u32> for Uint64

§

fn from(val: u32) -> Uint64

Converts to this type from the input type.
§

impl From<u64> for Uint64

§

fn from(val: u64) -> Uint64

Converts to this type from the input type.
§

impl From<u8> for Uint64

§

fn from(val: u8) -> Uint64

Converts to this type from the input type.
§

impl JsonSchema for Uint64

§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
§

fn json_schema(gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
§

impl Mul<&Uint64> for &Uint64

§

type Output = <Uint64 as Mul>::Output

The resulting type after applying the * operator.
§

fn mul(self, other: &Uint64) -> <Uint64 as Mul>::Output

Performs the * operation. Read more
§

impl Mul<&Uint64> for Uint64

§

type Output = <Uint64 as Mul>::Output

The resulting type after applying the * operator.
§

fn mul(self, other: &Uint64) -> <Uint64 as Mul>::Output

Performs the * operation. Read more
§

impl<'a> Mul<Uint64> for &'a Uint64

§

type Output = <Uint64 as Mul>::Output

The resulting type after applying the * operator.
§

fn mul(self, other: Uint64) -> <Uint64 as Mul>::Output

Performs the * operation. Read more
§

impl Mul for Uint64

§

type Output = Uint64

The resulting type after applying the * operator.
§

fn mul(self, rhs: Uint64) -> <Uint64 as Mul>::Output

Performs the * operation. Read more
§

impl MulAssign<&Uint64> for Uint64

§

fn mul_assign(&mut self, other: &Uint64)

Performs the *= operation. Read more
§

impl MulAssign for Uint64

§

fn mul_assign(&mut self, rhs: Uint64)

Performs the *= operation. Read more
§

impl Not for Uint64

§

type Output = Uint64

The resulting type after applying the ! operator.
§

fn not(self) -> <Uint64 as Not>::Output

Performs the unary ! operation. Read more
§

impl Ord for Uint64

§

fn cmp(&self, other: &Uint64) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
§

impl PartialEq<&Uint64> for Uint64

§

fn eq(&self, rhs: &&Uint64) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a> PartialEq<Uint64> for &'a Uint64

§

fn eq(&self, rhs: &Uint64) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq for Uint64

§

fn eq(&self, other: &Uint64) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialOrd for Uint64

§

fn partial_cmp(&self, other: &Uint64) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl Rem<&Uint64> for &Uint64

§

type Output = <Uint64 as Rem>::Output

The resulting type after applying the % operator.
§

fn rem(self, other: &Uint64) -> <Uint64 as Rem>::Output

Performs the % operation. Read more
§

impl Rem<&Uint64> for Uint64

§

type Output = <Uint64 as Rem>::Output

The resulting type after applying the % operator.
§

fn rem(self, other: &Uint64) -> <Uint64 as Rem>::Output

Performs the % operation. Read more
§

impl<'a> Rem<Uint64> for &'a Uint64

§

type Output = <Uint64 as Rem>::Output

The resulting type after applying the % operator.
§

fn rem(self, other: Uint64) -> <Uint64 as Rem>::Output

Performs the % operation. Read more
§

impl Rem for Uint64

§

fn rem(self, rhs: Uint64) -> Uint64

Panics

This operation will panic if rhs is zero.

§

type Output = Uint64

The resulting type after applying the % operator.
§

impl RemAssign<&Uint64> for Uint64

§

fn rem_assign(&mut self, other: &Uint64)

Performs the %= operation. Read more
§

impl RemAssign for Uint64

§

fn rem_assign(&mut self, rhs: Uint64)

Performs the %= operation. Read more
§

impl Serialize for Uint64

§

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> Shl<&'a u32> for Uint64

§

type Output = Uint64

The resulting type after applying the << operator.
§

fn shl(self, rhs: &'a u32) -> <Uint64 as Shl<&'a u32>>::Output

Performs the << operation. Read more
§

impl Shl<u32> for Uint64

§

type Output = Uint64

The resulting type after applying the << operator.
§

fn shl(self, rhs: u32) -> <Uint64 as Shl<u32>>::Output

Performs the << operation. Read more
§

impl<'a> ShlAssign<&'a u32> for Uint64

§

fn shl_assign(&mut self, rhs: &'a u32)

Performs the <<= operation. Read more
§

impl ShlAssign<u32> for Uint64

§

fn shl_assign(&mut self, rhs: u32)

Performs the <<= operation. Read more
§

impl<'a> Shr<&'a u32> for Uint64

§

type Output = Uint64

The resulting type after applying the >> operator.
§

fn shr(self, rhs: &'a u32) -> <Uint64 as Shr<&'a u32>>::Output

Performs the >> operation. Read more
§

impl Shr<u32> for Uint64

§

type Output = Uint64

The resulting type after applying the >> operator.
§

fn shr(self, rhs: u32) -> <Uint64 as Shr<u32>>::Output

Performs the >> operation. Read more
§

impl<'a> ShrAssign<&'a u32> for Uint64

§

fn shr_assign(&mut self, rhs: &'a u32)

Performs the >>= operation. Read more
§

impl ShrAssign<u32> for Uint64

§

fn shr_assign(&mut self, rhs: u32)

Performs the >>= operation. Read more
§

impl Sub<&Uint64> for &Uint64

§

type Output = <Uint64 as Sub>::Output

The resulting type after applying the - operator.
§

fn sub(self, other: &Uint64) -> <Uint64 as Sub>::Output

Performs the - operation. Read more
§

impl Sub<&Uint64> for Uint64

§

type Output = <Uint64 as Sub>::Output

The resulting type after applying the - operator.
§

fn sub(self, other: &Uint64) -> <Uint64 as Sub>::Output

Performs the - operation. Read more
§

impl<'a> Sub<Uint64> for &'a Uint64

§

type Output = <Uint64 as Sub>::Output

The resulting type after applying the - operator.
§

fn sub(self, other: Uint64) -> <Uint64 as Sub>::Output

Performs the - operation. Read more
§

impl Sub for Uint64

§

type Output = Uint64

The resulting type after applying the - operator.
§

fn sub(self, rhs: Uint64) -> Uint64

Performs the - operation. Read more
§

impl SubAssign<&Uint64> for Uint64

§

fn sub_assign(&mut self, other: &Uint64)

Performs the -= operation. Read more
§

impl SubAssign for Uint64

§

fn sub_assign(&mut self, rhs: Uint64)

Performs the -= operation. Read more
§

impl<A> Sum<A> for Uint64where Uint64: Add<A, Output = Uint64>,

§

fn sum<I>(iter: I) -> Uint64where I: Iterator<Item = A>,

Method which takes an iterator and generates Self from the elements by “summing up” the items.
§

impl TryFrom<&str> for Uint64

§

type Error = StdError

The type returned in the event of a conversion error.
§

fn try_from(val: &str) -> Result<Uint64, <Uint64 as TryFrom<&str>>::Error>

Performs the conversion.
§

impl TryFrom<Int128> for Uint64

§

type Error = ConversionOverflowError

The type returned in the event of a conversion error.
§

fn try_from(value: Int128) -> Result<Uint64, <Uint64 as TryFrom<Int128>>::Error>

Performs the conversion.
§

impl TryFrom<Int256> for Uint64

§

type Error = ConversionOverflowError

The type returned in the event of a conversion error.
§

fn try_from(value: Int256) -> Result<Uint64, <Uint64 as TryFrom<Int256>>::Error>

Performs the conversion.
§

impl TryFrom<Int512> for Uint64

§

type Error = ConversionOverflowError

The type returned in the event of a conversion error.
§

fn try_from(value: Int512) -> Result<Uint64, <Uint64 as TryFrom<Int512>>::Error>

Performs the conversion.
§

impl TryFrom<Int64> for Uint64

§

type Error = ConversionOverflowError

The type returned in the event of a conversion error.
§

fn try_from(value: Int64) -> Result<Uint64, <Uint64 as TryFrom<Int64>>::Error>

Performs the conversion.
§

impl TryFrom<Uint128> for Uint64

§

type Error = ConversionOverflowError

The type returned in the event of a conversion error.
§

fn try_from( value: Uint128 ) -> Result<Uint64, <Uint64 as TryFrom<Uint128>>::Error>

Performs the conversion.
§

impl TryFrom<Uint256> for Uint64

§

type Error = ConversionOverflowError

The type returned in the event of a conversion error.
§

fn try_from( value: Uint256 ) -> Result<Uint64, <Uint64 as TryFrom<Uint256>>::Error>

Performs the conversion.
§

impl TryFrom<Uint512> for Uint64

§

type Error = ConversionOverflowError

The type returned in the event of a conversion error.
§

fn try_from( value: Uint512 ) -> Result<Uint64, <Uint64 as TryFrom<Uint512>>::Error>

Performs the conversion.
§

impl Copy for Uint64

§

impl Eq for Uint64

§

impl StructuralEq for Uint64

§

impl StructuralPartialEq for Uint64

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<U> As for U

§

fn as_<T>(self) -> Twhere T: CastFrom<U>,

Casts 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 more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<I> Isqrt for Iwhere I: Div<Output = I> + Unsigned + Shr<u32, Output = I> + Add<Output = I> + PartialOrd + Copy + From<u8>,

§

fn isqrt(self) -> I

Algorithm adapted from Wikipedia.

§

impl<T> QueryResultExt for Twhere T: Serialize,

§

fn query_result(&self) -> Result<Binary, Error>

Convert the value to its JSON representation
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

§

impl<T, Rhs, Output> GroupOps<Rhs, Output> for Twhere T: Add<Rhs, Output = Output> + Sub<Rhs, Output = Output> + AddAssign<Rhs> + SubAssign<Rhs>,

§

impl<T, Rhs, Output> GroupOpsOwned<Rhs, Output> for Twhere T: for<'r> GroupOps<&'r Rhs, Output>,

§

impl<T, Rhs, Output> ScalarMul<Rhs, Output> for Twhere T: Mul<Rhs, Output = Output> + MulAssign<Rhs>,

§

impl<T, Rhs, Output> ScalarMulOwned<Rhs, Output> for Twhere T: for<'r> ScalarMul<&'r Rhs, Output>,