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
impl U256
Sourcepub const fn from_digits(digits: [u8; 32]) -> Self
pub const fn from_digits(digits: [u8; 32]) -> Self
Build a U256 directly from its 32 little-endian digits.
Sourcepub const fn from_le(value: Self) -> Self
pub const fn from_le(value: Self) -> Self
Reverse the byte order of value on big-endian targets; identity on
little-endian targets.
Sourcepub const fn from_be(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Reverse the byte order of value on little-endian targets; identity on
big-endian targets.
Sourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Reverse the byte order on big-endian targets; identity on little-endian targets.
Sourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Reverse the byte order on little-endian targets; identity on big-endian targets.
Sourcepub const fn from_str_radix(s: &str, radix: u32) -> Result<Self, U256ParseError>
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.
Sourcepub fn to_str_radix(&self, radix: u32) -> String
pub fn to_str_radix(&self, radix: u32) -> String
Render the value in the given radix. radix must be in the range 2..=36.
Sourcepub fn from_radix_be(buf: &[u8], radix: u32) -> Option<Self>
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.
Sourcepub fn to_radix_be(&self, radix: u32) -> Vec<u8> ⓘ
pub fn to_radix_be(&self, radix: u32) -> Vec<u8> ⓘ
Render the value as a sequence of big-endian digits in the given radix.
Sourcepub fn from_le_slice(slice: &[u8]) -> Option<Self>
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<'de> Deserialize<'de> for U256
Available on crate feature serde only.
impl<'de> Deserialize<'de> for U256
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Ord for U256
impl Ord for U256
Source§impl PartialOrd for U256
impl PartialOrd for U256
impl Copy for U256
impl Eq for U256
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§
§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: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, T> FromBcs for Twhere
T: Deserialize<'de>,
impl<'de, T> FromBcs for Twhere
T: Deserialize<'de>,
Source§fn from_bcs<'de>(bytes: &'de [u8]) -> Result<Self, Error>where
Self: Deserialize<'de>,
fn from_bcs<'de>(bytes: &'de [u8]) -> Result<Self, Error>where
Self: Deserialize<'de>,
serde only.Source§fn from_bcs_base64(base64: &str) -> Result<Self, Error>where
Self: DeserializeOwned,
fn from_bcs_base64(base64: &str) -> Result<Self, Error>where
Self: DeserializeOwned,
serde only.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