pub struct Uint256(_);
Expand description

An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.

Examples

Use from to create instances out of primitive uint types or new to provide big endian bytes:

let a = Uint256::from(258u128);
let b = Uint256::new([
    0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
    0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
    0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
    0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8,
]);
assert_eq!(a, b);

Implementations§

source§

impl Uint256

source

pub const MAX: Uint256 = _

source

pub const MIN: Uint256 = _

source

pub const fn new(value: [u8; 32]) -> Self

Creates a Uint256(value) from a big endian representation. It’s just an alias for Uint256::from_be_bytes.

This method is less flexible than from but can be called in a const context.

source

pub const fn zero() -> Self

Creates a Uint256(0)

source

pub const fn one() -> Self

Creates a Uint256(1)

source

pub const fn from_be_bytes(data: [u8; 32]) -> Self

source

pub const fn from_le_bytes(data: [u8; 32]) -> Self

source

pub const fn from_u128(num: u128) -> Self

A conversion from u128 that, unlike the one provided by the From trait, can be used in a const context.

source

pub const fn from_uint128(num: Uint128) -> Self

A conversion from Uint128 that, unlike the one provided by the From trait, can be used in a const context.

source

pub const fn to_be_bytes(self) -> [u8; 32]

Returns a copy of the number as big endian bytes.

source

pub const fn to_le_bytes(self) -> [u8; 32]

Returns a copy of the number as little endian bytes.

source

pub const fn is_zero(&self) -> bool

source

pub fn pow(self, exp: u32) -> Self

source

pub fn multiply_ratio<A: Into<Uint256>, B: Into<Uint256>>( &self, numerator: A, denominator: B ) -> Uint256

Returns self * numerator / denominator.

Due to the nature of the integer division involved, the result is always floored. E.g. 5 * 99/100 = 4.

source

pub fn checked_multiply_ratio<A: Into<Uint256>, B: Into<Uint256>>( &self, numerator: A, denominator: B ) -> Result<Uint256, 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.

source

pub fn full_mul(self, rhs: impl Into<Uint256>) -> Uint512

Multiplies two u256 values without overflow, producing an Uint512.

Examples
use secret_cosmwasm_std::Uint256;

let a = Uint256::MAX;
let result = a.full_mul(2u32);
assert_eq!(
    result.to_string(),
    "231584178474632390847141970017375815706539969331281128078915168015826259279870",
);
source

pub fn checked_add(self, other: Self) -> Result<Self, OverflowError>

source

pub fn checked_sub(self, other: Self) -> Result<Self, OverflowError>

source

pub fn checked_mul(self, other: Self) -> Result<Self, OverflowError>

source

pub fn checked_pow(self, exp: u32) -> Result<Self, OverflowError>

source

pub fn checked_div(self, other: Self) -> Result<Self, DivideByZeroError>

source

pub fn checked_div_euclid(self, other: Self) -> Result<Self, DivideByZeroError>

source

pub fn checked_rem(self, other: Self) -> Result<Self, DivideByZeroError>

source

pub fn checked_shr(self, other: u32) -> Result<Self, OverflowError>

source

pub fn checked_shl(self, other: u32) -> Result<Self, OverflowError>

source

pub fn wrapping_add(self, other: Self) -> Self

source

pub fn wrapping_sub(self, other: Self) -> Self

source

pub fn wrapping_mul(self, other: Self) -> Self

source

pub fn wrapping_pow(self, other: u32) -> Self

source

pub fn saturating_add(self, other: Self) -> Self

source

pub fn saturating_sub(self, other: Self) -> Self

source

pub fn saturating_mul(self, other: Self) -> Self

source

pub fn saturating_pow(self, exp: u32) -> Self

source

pub fn abs_diff(self, other: Self) -> Self

Trait Implementations§

source§

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

§

type Output = Uint256

The resulting type after applying the + operator.
source§

fn add(self, rhs: &'a Uint256) -> Self

Performs the + operation. Read more
source§

impl Add<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

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

source§

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

Performs the += operation. Read more
source§

impl AddAssign<Uint256> for Uint256

source§

fn add_assign(&mut self, rhs: Uint256)

Performs the += operation. Read more
source§

impl Clone for Uint256

source§

fn clone(&self) -> Uint256

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

impl Debug for Uint256

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Uint256

source§

fn default() -> Uint256

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

impl<'de> Deserialize<'de> for Uint256

source§

fn deserialize<D>(deserializer: D) -> Result<Uint256, D::Error>where D: Deserializer<'de>,

Deserialized from an integer string using base 10

source§

impl Display for Uint256

source§

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

Formats the value using the given formatter. Read more
source§

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

§

type Output = Uint256

The resulting type after applying the / operator.
source§

fn div(self, rhs: &'a Uint256) -> Self::Output

Performs the / operation. Read more
source§

impl Div<Uint256> for Decimal256

§

type Output = Decimal256

The resulting type after applying the / operator.
source§

fn div(self, rhs: Uint256) -> Self::Output

Performs the / operation. Read more
source§

impl Div<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
source§

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

source§

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

Performs the /= operation. Read more
source§

impl DivAssign<Uint256> for Decimal256

source§

fn div_assign(&mut self, rhs: Uint256)

Performs the /= operation. Read more
source§

impl DivAssign<Uint256> for Uint256

source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
source§

impl Fraction<Uint256> for Decimal256

source§

fn inv(&self) -> Option<Self>

Returns the multiplicative inverse 1/d for decimal d.

If d is zero, none is returned.

source§

fn numerator(&self) -> Uint256

Returns the numerator p
source§

fn denominator(&self) -> Uint256

Returns the denominator q
source§

impl From<Uint128> for Uint256

source§

fn from(val: Uint128) -> Self

Converts to this type from the input type.
source§

impl From<Uint256> for String

source§

fn from(original: Uint256) -> Self

Converts to this type from the input type.
source§

impl From<Uint256> for Uint512

source§

fn from(val: Uint256) -> Self

Converts to this type from the input type.
source§

impl From<Uint64> for Uint256

source§

fn from(val: Uint64) -> Self

Converts to this type from the input type.
source§

impl From<u128> for Uint256

source§

fn from(val: u128) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Uint256

source§

fn from(val: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Uint256

source§

fn from(val: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Uint256

source§

fn from(val: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Uint256

source§

fn from(val: u8) -> Self

Converts to this type from the input type.
source§

impl FromStr for Uint256

§

type Err = StdError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl JsonSchema for Uint256

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

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

Generates a JSON Schema for this type. Read more
source§

fn is_referenceable() -> bool

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

impl Mul<&Uint256> for &Uint256

§

type Output = <Uint256 as Mul<Uint256>>::Output

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<&Uint256> for Uint256

§

type Output = <Uint256 as Mul<Uint256>>::Output

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Decimal256> for Uint256

Both du and ud with d: Decimal256 and u: Uint256 returns an Uint256. There is no specific reason for this decision other than the initial use cases we have. If you need a Decimal256 result for the same calculation, use Decimal256(du) or Decimal256(ud).

§

type Output = Uint256

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Decimal256) -> Self::Output

Performs the * operation. Read more
source§

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

§

type Output = <Uint256 as Mul<Uint256>>::Output

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Uint256> for Decimal256

§

type Output = Uint256

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Uint256) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign<&Uint256> for Uint256

source§

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

Performs the *= operation. Read more
source§

impl MulAssign<Uint256> for Uint256

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl Ord for Uint256

source§

fn cmp(&self, other: &Uint256) -> 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<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<&Uint256> for Uint256

source§

fn eq(&self, rhs: &&Uint256) -> 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.
source§

impl PartialEq<Uint256> for &Uint256

source§

fn eq(&self, rhs: &Uint256) -> 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.
source§

impl PartialEq<Uint256> for Uint256

source§

fn eq(&self, other: &Uint256) -> 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.
source§

impl PartialOrd<Uint256> for Uint256

source§

fn partial_cmp(&self, other: &Uint256) -> 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
source§

impl Rem<&Uint256> for &Uint256

§

type Output = <Uint256 as Rem<Uint256>>::Output

The resulting type after applying the % operator.
source§

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

Performs the % operation. Read more
source§

impl Rem<&Uint256> for Uint256

§

type Output = <Uint256 as Rem<Uint256>>::Output

The resulting type after applying the % operator.
source§

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

Performs the % operation. Read more
source§

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

§

type Output = <Uint256 as Rem<Uint256>>::Output

The resulting type after applying the % operator.
source§

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

Performs the % operation. Read more
source§

impl Rem<Uint256> for Uint256

source§

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

Panics

This operation will panic if rhs is zero.

§

type Output = Uint256

The resulting type after applying the % operator.
source§

impl RemAssign<&Uint256> for Uint256

source§

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

Performs the %= operation. Read more
source§

impl RemAssign<Uint256> for Uint256

source§

fn rem_assign(&mut self, rhs: Uint256)

Performs the %= operation. Read more
source§

impl Serialize for Uint256

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serializes as an integer string using base 10

source§

impl<'a> Shl<&'a u32> for Uint256

§

type Output = Uint256

The resulting type after applying the << operator.
source§

fn shl(self, rhs: &'a u32) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<u32> for Uint256

§

type Output = Uint256

The resulting type after applying the << operator.
source§

fn shl(self, rhs: u32) -> Self::Output

Performs the << operation. Read more
source§

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

§

type Output = Uint256

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: &'a u32) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<u32> for Uint256

§

type Output = Uint256

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: u32) -> Self::Output

Performs the >> operation. Read more
source§

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

source§

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

Performs the >>= operation. Read more
source§

impl ShrAssign<u32> for Uint256

source§

fn shr_assign(&mut self, rhs: u32)

Performs the >>= operation. Read more
source§

impl Sub<&Uint256> for &Uint256

§

type Output = <Uint256 as Sub<Uint256>>::Output

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<&Uint256> for Uint256

§

type Output = <Uint256 as Sub<Uint256>>::Output

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

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

§

type Output = <Uint256 as Sub<Uint256>>::Output

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl SubAssign<&Uint256> for Uint256

source§

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

Performs the -= operation. Read more
source§

impl SubAssign<Uint256> for Uint256

source§

fn sub_assign(&mut self, rhs: Uint256)

Performs the -= operation. Read more
source§

impl<A> Sum<A> for Uint256where Self: Add<A, Output = Self>,

source§

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

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

impl TryFrom<&str> for Uint256

§

type Error = StdError

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

fn try_from(val: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Uint256> for Uint128

§

type Error = ConversionOverflowError

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

fn try_from(value: Uint256) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Uint512> for Uint256

§

type Error = ConversionOverflowError

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

fn try_from(value: Uint512) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Uint256

source§

impl Eq for Uint256

source§

impl StructuralEq for Uint256

source§

impl StructuralPartialEq for Uint256

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

source§

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

source§

fn isqrt(self) -> I

Algorithm adapted from Wikipedia.

source§

impl<T> Same<T> 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>,