Struct cosmwasm_std::Uint256
source · [−]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
sourceimpl Uint256
impl Uint256
pub const MAX: Uint256 = _
pub const MIN: Uint256 = _
sourcepub const fn new(value: [u8; 32]) -> Self
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.
pub const fn from_be_bytes(data: [u8; 32]) -> Self
pub const fn from_le_bytes(data: [u8; 32]) -> Self
sourcepub const fn from_u128(num: u128) -> Self
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.
sourcepub const fn from_uint128(num: Uint128) -> Self
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.
sourcepub const fn to_be_bytes(self) -> [u8; 32]
pub const fn to_be_bytes(self) -> [u8; 32]
Returns a copy of the number as big endian bytes.
sourcepub const fn to_le_bytes(self) -> [u8; 32]
pub const fn to_le_bytes(self) -> [u8; 32]
Returns a copy of the number as little endian bytes.
pub const fn is_zero(&self) -> bool
pub fn pow(self, exp: u32) -> Self
sourcepub fn multiply_ratio<A: Into<Uint256>, B: Into<Uint256>>(
&self,
numerator: A,
denominator: B
) -> Uint256
pub fn multiply_ratio<A: Into<Uint256>, B: Into<Uint256>>(
&self,
numerator: A,
denominator: B
) -> Uint256
Returns self * numerator / denominator
sourcepub fn checked_multiply_ratio<A: Into<Uint256>, B: Into<Uint256>>(
&self,
numerator: A,
denominator: B
) -> Result<Uint256, CheckedMultiplyRatioError>
pub fn checked_multiply_ratio<A: Into<Uint256>, B: Into<Uint256>>(
&self,
numerator: A,
denominator: B
) -> Result<Uint256, CheckedMultiplyRatioError>
Returns self * numerator / denominator
pub fn checked_add(self, other: Self) -> Result<Self, OverflowError>
pub fn checked_sub(self, other: Self) -> Result<Self, OverflowError>
pub fn checked_mul(self, other: Self) -> Result<Self, OverflowError>
pub fn checked_pow(self, exp: u32) -> Result<Self, OverflowError>
pub fn checked_div(self, other: Self) -> Result<Self, DivideByZeroError>
pub fn checked_div_euclid(self, other: Self) -> Result<Self, DivideByZeroError>
pub fn checked_rem(self, other: Self) -> Result<Self, DivideByZeroError>
pub fn checked_shr(self, other: u32) -> Result<Self, OverflowError>
pub fn checked_shl(self, other: u32) -> Result<Self, OverflowError>
pub fn wrapping_add(self, other: Self) -> Self
pub fn wrapping_sub(self, other: Self) -> Self
pub fn wrapping_mul(self, other: Self) -> Self
pub fn wrapping_pow(self, other: u32) -> Self
pub fn saturating_add(self, other: Self) -> Self
pub fn saturating_sub(self, other: Self) -> Self
pub fn saturating_mul(self, other: Self) -> Self
pub fn saturating_pow(self, exp: u32) -> Self
pub fn abs_diff(self, other: Self) -> Self
Trait Implementations
sourceimpl<'a> AddAssign<&'a Uint256> for Uint256
impl<'a> AddAssign<&'a Uint256> for Uint256
sourcefn add_assign(&mut self, rhs: &'a Uint256)
fn add_assign(&mut self, rhs: &'a Uint256)
+=
operation. Read moresourceimpl AddAssign<Uint256> for Uint256
impl AddAssign<Uint256> for Uint256
sourcefn add_assign(&mut self, rhs: Uint256)
fn add_assign(&mut self, rhs: Uint256)
+=
operation. Read moresourceimpl<'de> Deserialize<'de> for Uint256
impl<'de> Deserialize<'de> for Uint256
sourcefn deserialize<D>(deserializer: D) -> Result<Uint256, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Uint256, D::Error>where
D: Deserializer<'de>,
Deserialized from an integer string using base 10
sourceimpl Div<Uint256> for Decimal256
impl Div<Uint256> for Decimal256
sourceimpl<'a> DivAssign<&'a Uint256> for Uint256
impl<'a> DivAssign<&'a Uint256> for Uint256
sourcefn div_assign(&mut self, rhs: &'a Uint256)
fn div_assign(&mut self, rhs: &'a Uint256)
/=
operation. Read moresourceimpl DivAssign<Uint256> for Decimal256
impl DivAssign<Uint256> for Decimal256
sourcefn div_assign(&mut self, rhs: Uint256)
fn div_assign(&mut self, rhs: Uint256)
/=
operation. Read moresourceimpl DivAssign<Uint256> for Uint256
impl DivAssign<Uint256> for Uint256
sourcefn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresourceimpl Fraction<Uint256> for Decimal256
impl Fraction<Uint256> for Decimal256
sourceimpl JsonSchema for Uint256
impl JsonSchema for Uint256
sourcefn schema_name() -> String
fn schema_name() -> String
sourcefn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
sourcefn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresourceimpl Mul<Decimal256> for Uint256
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).
sourceimpl Mul<Uint256> for Decimal256
impl Mul<Uint256> for Decimal256
sourceimpl MulAssign<&Uint256> for Uint256
impl MulAssign<&Uint256> for Uint256
sourcefn mul_assign(&mut self, other: &Uint256)
fn mul_assign(&mut self, other: &Uint256)
*=
operation. Read moresourceimpl MulAssign<Uint256> for Uint256
impl MulAssign<Uint256> for Uint256
sourcefn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresourceimpl Ord for Uint256
impl Ord for Uint256
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialOrd<Uint256> for Uint256
impl PartialOrd<Uint256> for Uint256
sourcefn partial_cmp(&self, other: &Uint256) -> Option<Ordering>
fn partial_cmp(&self, other: &Uint256) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl RemAssign<&Uint256> for Uint256
impl RemAssign<&Uint256> for Uint256
sourcefn rem_assign(&mut self, other: &Uint256)
fn rem_assign(&mut self, other: &Uint256)
%=
operation. Read moresourceimpl RemAssign<Uint256> for Uint256
impl RemAssign<Uint256> for Uint256
sourcefn rem_assign(&mut self, rhs: Uint256)
fn rem_assign(&mut self, rhs: Uint256)
%=
operation. Read moresourceimpl<'a> ShrAssign<&'a u32> for Uint256
impl<'a> ShrAssign<&'a u32> for Uint256
sourcefn shr_assign(&mut self, rhs: &'a u32)
fn shr_assign(&mut self, rhs: &'a u32)
>>=
operation. Read moresourceimpl ShrAssign<u32> for Uint256
impl ShrAssign<u32> for Uint256
sourcefn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>=
operation. Read moresourceimpl SubAssign<&Uint256> for Uint256
impl SubAssign<&Uint256> for Uint256
sourcefn sub_assign(&mut self, other: &Uint256)
fn sub_assign(&mut self, other: &Uint256)
-=
operation. Read moresourceimpl SubAssign<Uint256> for Uint256
impl SubAssign<Uint256> for Uint256
sourcefn sub_assign(&mut self, rhs: Uint256)
fn sub_assign(&mut self, rhs: Uint256)
-=
operation. Read more