Skip to main content

U256

Struct U256 

Source
pub struct U256(/* private fields */);
Expand description

A 256-bit unsigned integer matching Move’s u256 primitive type.

The in-memory layout is 32 bytes in little-endian order. When the serde feature is enabled, the BCS encoding is those same 32 little-endian bytes, matching the on-chain representation used by Move.

Implementations§

Source§

impl U256

Source

pub const ZERO: Self

The additive identity, 0.

Source

pub const ONE: Self

The multiplicative identity, 1.

Source

pub const fn from_digits(digits: [u8; 32]) -> Self

Build a U256 directly from its 32 little-endian digits.

Source

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

Borrow the underlying 32 bytes in little-endian order.

Source

pub const fn from_le(value: Self) -> Self

Reverse the byte order of value on big-endian targets; identity on little-endian targets.

Source

pub const fn from_be(value: Self) -> Self

Reverse the byte order of value on little-endian targets; identity on big-endian targets.

Source

pub const fn to_le(self) -> Self

Reverse the byte order on big-endian targets; identity on little-endian targets.

Source

pub const fn to_be(self) -> Self

Reverse the byte order on little-endian targets; identity on big-endian targets.

Source

pub const fn from_str_radix(s: &str, radix: u32) -> Result<Self, U256ParseError>

Parse a string in the given radix. radix must be in the range 2..=36.

Source

pub fn to_str_radix(&self, radix: u32) -> String

Render the value in the given radix. radix must be in the range 2..=36.

Source

pub fn from_radix_be(buf: &[u8], radix: u32) -> Option<Self>

Build a U256 from a slice of big-endian digits in the given radix. Returns None if any digit is out of range for radix or if the resulting value would overflow 256 bits.

Source

pub fn to_radix_be(&self, radix: u32) -> Vec<u8>

Render the value as a sequence of big-endian digits in the given radix.

Source

pub fn from_le_slice(slice: &[u8]) -> Option<Self>

Build a U256 from up to 32 little-endian bytes. Returns None if the slice is longer than 32 bytes.

Trait Implementations§

Source§

impl Clone for U256

Source§

fn clone(&self) -> U256

Returns a duplicate 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 U256

Source§

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

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

impl Default for U256

Source§

fn default() -> U256

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

impl<'de> Deserialize<'de> for U256

Available on crate feature serde only.
Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for U256

Source§

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

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

impl From<u64> for U256

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for U256

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl FromStr for U256

Source§

type Err = U256ParseError

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 Hash for U256

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for U256

Source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for U256

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl PartialOrd for U256

Source§

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

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

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

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

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

impl Serialize for U256

Available on crate feature serde only.
Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for U256

Source§

impl Eq for U256

Source§

impl StructuralPartialEq for U256

Auto Trait Implementations§

§

impl Freeze for U256

§

impl RefUnwindSafe for U256

§

impl Send for U256

§

impl Sync for U256

§

impl Unpin for U256

§

impl UnsafeUnpin for U256

§

impl UnwindSafe for U256

Blanket Implementations§

Source§

impl<T> Any for T
where 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) -> T
where 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 T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'de, T> FromBcs for T
where T: Deserialize<'de>,

Source§

fn from_bcs<'de>(bytes: &'de [u8]) -> Result<Self, Error>
where Self: Deserialize<'de>,

Available on crate feature serde only.
Source§

fn from_bcs_base64(base64: &str) -> Result<Self, Error>
where Self: DeserializeOwned,

Available on crate feature serde only.
Source§

impl<T, U> Into<U> for T
where 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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToBcs for T
where T: Serialize,

Source§

fn to_bcs(&self) -> Result<Vec<u8>, Error>

Available on crate feature serde only.
Source§

fn to_bcs_base64(&self) -> Result<String, Error>

Available on crate feature serde only.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

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