pub struct U256(pub Uint<4>);Tuple Fields§
§0: Uint<4>Implementations§
Source§impl U256
impl U256
pub fn from_usize_array(x: [usize; 8]) -> Self
pub fn to_usize_array(self) -> [usize; 8]
pub const fn from_usize(x: usize) -> Self
pub const fn resize_to_usize(self) -> usize
pub fn try_resize_to_usize(self) -> Option<usize>
Source§impl U256
impl U256
pub fn from_hex_str_fast(src: &[u8]) -> Result<Self, FromStrRadixErr>
pub const fn from_bytes_radix( src: &[u8], radix: u8, ) -> Result<Self, FromStrRadixErr>
pub const fn from_str_radix( src: &str, radix: u8, ) -> Result<Self, FromStrRadixErr>
Sourcepub fn from_dec_or_hex_str(src: &str) -> Result<Self, FromStrRadixErr>
pub fn from_dec_or_hex_str(src: &str) -> Result<Self, FromStrRadixErr>
Uses radix 16 if src has a leading 0x, otherwise uses radix 10
The uint implementation of FromStr is unsuitable because it is
hexadecimal only (intentional by their developers because they did not
make the mistake of using decimal in message passing implementations and
do not have wasteful “0x” prefixes), this function will switch between
hexadecimal and decimal depending on if there is a “0x” prefix.
Sourcepub fn from_dec_or_hex_str_restricted(
src: &str,
) -> Result<Self, FromStrRadixErr>
pub fn from_dec_or_hex_str_restricted( src: &str, ) -> Result<Self, FromStrRadixErr>
Same as from_dec_or_hex_str but may not allow for ‘_’ or more than 78
bytes
Sourcepub fn to_hex_string_buffer(self, buf: &mut [u64; 8]) -> usize
pub fn to_hex_string_buffer(self, buf: &mut [u64; 8]) -> usize
This function is intended for formatting intermediates that use stack buffers.
Assigns a hex representation of self to buf[index..] (cast as a byte
array with bytemuck) and returns the index. No prefix or minimum
“0” are set (returns 64 if self.is_zero()). Also, bytes in
buf[..index] may be set arbitrarily. Only
b’0’-b’9’ and b’a’-b’f’ can be output to buf[index..].
Sourcepub fn to_hex_string(self) -> String
pub fn to_hex_string(self) -> String
Returns a hexadecimal string representation of self, including a “0x”
prefix. If self.is_zero(), this returns “0x0”
Sourcepub fn to_bytes_radix(self, radix: u8, upper: bool) -> Option<Vec<u8>>
pub fn to_bytes_radix(self, radix: u8, upper: bool) -> Option<Vec<u8>>
Prefixes not included. Note: if self.is_zero, the Vec is empty.
Returns None if the radix is not valid
pub fn to_dec_string(self) -> String
Sourcepub const fn checked_exp10(exp: usize) -> Option<Self>
pub const fn checked_exp10(exp: usize) -> Option<Self>
Returns 10^exp, or None if overflow occurs
Source§impl U256
impl U256
pub fn from_u8_array(x: [u8; 32]) -> Self
pub fn to_u8_array(self) -> [u8; 32]
pub fn from_u16_array(x: [u16; 16]) -> Self
pub fn to_u16_array(self) -> [u16; 16]
pub fn from_u32_array(x: [u32; 8]) -> Self
pub fn to_u32_array(self) -> [u32; 8]
pub fn from_u128_array(x: [u128; 2]) -> Self
pub fn to_u128_array(self) -> [u128; 2]
pub const fn from_u8(x: u8) -> Self
pub const fn resize_to_u8(self) -> u8
pub const fn from_u16(x: u16) -> Self
pub const fn resize_to_u16(self) -> u16
pub const fn from_u32(x: u32) -> Self
pub const fn resize_to_u32(self) -> u32
pub const fn from_u64(x: u64) -> Self
pub const fn resize_to_u64(self) -> u64
pub const fn try_resize_to_bool(self) -> Option<bool>
pub const fn try_resize_to_u8(self) -> Option<u8>
pub const fn try_resize_to_u16(self) -> Option<u16>
pub const fn try_resize_to_u32(self) -> Option<u32>
pub const fn try_resize_to_u64(self) -> Option<u64>
pub const fn try_resize_to_u128(self) -> Option<u128>
pub const fn from_u64_array(x: [u64; 4]) -> Self
pub const fn to_u64_array(self) -> [u64; 4]
pub const fn from_bool(x: bool) -> Self
pub const fn resize_to_bool(self) -> bool
pub const fn from_u128(x: u128) -> Self
pub const fn resize_to_u128(self) -> u128
pub const fn zero() -> Self
pub const fn one() -> Self
pub const fn max_value() -> Self
pub const fn is_zero(self) -> bool
Sourcepub fn as_u8_slice_mut(&mut self) -> &mut [u8; 32]
pub fn as_u8_slice_mut(&mut self) -> &mut [u8; 32]
This gives a straight byte slice view into self, be aware that it
changes on big endian systems
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Note: this is an identity:
U256::from_bytes(&x0.to_u8_array()[..(32 - (x0.lz() / 8))]).unwrap()
§Errors
If the number of bytes is greater than the number of bytes in Self
Sourcepub fn from_bytes_be(bytes: &[u8]) -> Option<Self>
pub fn from_bytes_be(bytes: &[u8]) -> Option<Self>
Note: this is an identity:
U256::from_bytes_be(&x0.to_u8_array_be()[(x0.lz() / 8)..]).unwrap()
§Errors
If the number of bytes is greater than the number of bytes in Self
pub fn from_u8_array_be(x: [u8; 32]) -> Self
pub fn to_u8_array_be(self) -> [u8; 32]
pub const fn overflowing_add(self, other: Self) -> (Self, bool)
pub const fn overflowing_sub(self, other: Self) -> (Self, bool)
pub const fn overflowing_mul(self, other: Self) -> (Self, bool)
pub const fn wrapping_add(self, other: Self) -> Self
pub const fn wrapping_sub(self, other: Self) -> Self
pub const fn wrapping_mul(self, other: Self) -> Self
pub const fn wrapping_shl(self, s: usize) -> Self
pub const fn wrapping_shr(self, s: usize) -> Self
pub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_shl(self, s: usize) -> Option<Self>
pub const fn checked_shr(self, s: usize) -> Option<Self>
Sourcepub const fn shl1(self) -> Option<Self>
pub const fn shl1(self) -> Option<Self>
Shift left by 1. Returns None if numerical overflow results
pub const fn checked_rotl(self, s: usize) -> Option<Self>
Sourcepub fn rand_using<R>(rng: &mut R) -> Selfwhere
R: RngCore,
pub fn rand_using<R>(rng: &mut R) -> Selfwhere
R: RngCore,
Randomly-assigns self using a rand_core::RngCore random number
generator
// Example using the `rand_xoshiro` crate.
use rand_xoshiro::{rand_core::SeedableRng, Xoshiro128StarStar};
use u64_array_bigints::U256;
let mut rng = Xoshiro128StarStar::seed_from_u64(0);
assert_eq!(
U256::rand_using(&mut rng),
U256::from_u64_array([
0x9a089d75dec9045d,
0xc3e16405ab77d362,
0x60dea0565c95a8da,
0xa4290614c25a5140,
])
);Source§impl U256
These are forwarded from Uint<4>
impl U256
These are forwarded from Uint<4>
pub const fn bw() -> usize
pub const fn lsb(&self) -> bool
pub const fn msb(&self) -> bool
pub const fn lz(&self) -> usize
pub const fn tz(&self) -> usize
pub const fn count_ones(&self) -> usize
pub const fn const_eq(&self, rhs: &Self) -> bool
pub const fn const_lt(&self, rhs: &Self) -> bool
pub const fn const_le(&self, rhs: &Self) -> bool
pub const fn const_gt(&self, rhs: &Self) -> bool
pub const fn const_ge(&self, rhs: &Self) -> bool
pub const fn overflowing_short_cin_mul(self, cin: u64, rhs: u64) -> (Self, u64)
pub const fn overflowing_short_mul_add( self, lhs: Self, rhs: u64, ) -> (Self, bool)
pub const fn overflowing_mul_add(self, lhs: Self, rhs: Self) -> (Self, bool)
pub const fn checked_short_divide(self, div: u64) -> Option<(Self, u64)>
pub const fn panicking_short_divide(self, div: u64) -> (Self, u64)
pub const fn divide(self, div: Self) -> Option<(Self, Self)>
Trait Implementations§
Source§impl BitAndAssign for U256
impl BitAndAssign for U256
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitOrAssign for U256
impl BitOrAssign for U256
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitXorAssign for U256
impl BitXorAssign for U256
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl<'de> Deserialize<'de> for U256
Available on crate feature serde_support only.
impl<'de> Deserialize<'de> for U256
serde_support only.Source§fn deserialize<D>(deserializer: D) -> Result<U256, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<U256, D::Error>where
D: Deserializer<'de>,
Tries Deserializer::deserialize_str and feeds it to
from_dec_or_hex_str_restricted, else uses
Deserializer::deserialize_u64.