Struct u64_array_bigints_core::U256
source · [−]pub struct U256(pub Uint<4>);Tuple Fields
0: Uint<4>Implementations
sourceimpl 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>
sourceimpl 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
sourceimpl 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) -> Self where
R: RngCore,
pub fn rand_using<R>(rng: &mut R) -> Self where
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,
])
);sourceimpl U256
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
sourceimpl BitAndAssign<U256> for U256
impl BitAndAssign<U256> for U256
sourcefn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
Performs the &= operation. Read more
sourceimpl BitOrAssign<U256> for U256
impl BitOrAssign<U256> for U256
sourcefn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
Performs the |= operation. Read more
sourceimpl BitXorAssign<U256> for U256
impl BitXorAssign<U256> for U256
sourcefn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
Performs the ^= operation. Read more
sourceimpl<'de> Deserialize<'de> for U256
impl<'de> Deserialize<'de> for U256
sourcefn 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>,
Uses from_dec_or_hex_str_restricted.
sourceimpl Ord for U256
impl Ord for U256
sourceimpl PartialOrd<U256> for U256
impl PartialOrd<U256> for U256
sourcefn partial_cmp(&self, other: &U256) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
impl Copy for U256
impl Eq for U256
impl StructuralEq for U256
impl StructuralPartialEq for U256
Auto Trait Implementations
impl RefUnwindSafe for U256
impl Send for U256
impl Sync for U256
impl Unpin for U256
impl UnwindSafe for U256
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more