Struct u64_array_bigints::U256
source · pub struct U256(pub Uint<4>);
Tuple Fields§
§0: Uint<4>
Implementations§
source§impl U256
impl U256
pub fn from_usize_array(x: [usize; 4]) -> U256
pub fn to_usize_array(self) -> [usize; 4]
pub const fn from_usize(x: usize) -> U256
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<U256, FromStrRadixErr>
pub const fn from_bytes_radix( src: &[u8], radix: u8 ) -> Result<U256, FromStrRadixErr>
pub const fn from_str_radix( src: &str, radix: u8 ) -> Result<U256, FromStrRadixErr>
sourcepub fn from_dec_or_hex_str(src: &str) -> Result<U256, FromStrRadixErr>
pub fn from_dec_or_hex_str(src: &str) -> Result<U256, 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<U256, FromStrRadixErr>
pub fn from_dec_or_hex_str_restricted( src: &str ) -> Result<U256, 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, Global>>
pub fn to_bytes_radix(self, radix: u8, upper: bool) -> Option<Vec<u8, Global>>
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<U256>
pub const fn checked_exp10(exp: usize) -> Option<U256>
Returns 10^exp
, or None
if overflow occurs
source§impl U256
impl U256
pub fn from_u8_array(x: [u8; 32]) -> U256
pub fn to_u8_array(self) -> [u8; 32]
pub fn from_u16_array(x: [u16; 16]) -> U256
pub fn to_u16_array(self) -> [u16; 16]
pub fn from_u32_array(x: [u32; 8]) -> U256
pub fn to_u32_array(self) -> [u32; 8]
pub fn from_u128_array(x: [u128; 2]) -> U256
pub fn to_u128_array(self) -> [u128; 2]
pub const fn from_u8(x: u8) -> U256
pub const fn resize_to_u8(self) -> u8
pub const fn from_u16(x: u16) -> U256
pub const fn resize_to_u16(self) -> u16
pub const fn from_u32(x: u32) -> U256
pub const fn resize_to_u32(self) -> u32
pub const fn from_u64(x: u64) -> U256
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]) -> U256
pub const fn to_u64_array(self) -> [u64; 4]
pub const fn from_bool(x: bool) -> U256
pub const fn resize_to_bool(self) -> bool
pub const fn from_u128(x: u128) -> U256
pub const fn resize_to_u128(self) -> u128
pub const fn zero() -> U256
pub const fn one() -> U256
pub const fn max_value() -> U256
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<U256>
pub fn from_bytes(bytes: &[u8]) -> Option<U256>
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<U256>
pub fn from_bytes_be(bytes: &[u8]) -> Option<U256>
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]) -> U256
pub fn to_u8_array_be(self) -> [u8; 32]
pub const fn overflowing_add(self, other: U256) -> (U256, bool)
pub const fn overflowing_sub(self, other: U256) -> (U256, bool)
pub const fn overflowing_mul(self, other: U256) -> (U256, bool)
pub const fn wrapping_add(self, other: U256) -> U256
pub const fn wrapping_sub(self, other: U256) -> U256
pub const fn wrapping_mul(self, other: U256) -> U256
pub const fn wrapping_shl(self, s: usize) -> U256
pub const fn wrapping_shr(self, s: usize) -> U256
pub const fn checked_add(self, rhs: U256) -> Option<U256>
pub const fn checked_sub(self, rhs: U256) -> Option<U256>
pub const fn checked_mul(self, rhs: U256) -> Option<U256>
pub const fn checked_shl(self, s: usize) -> Option<U256>
pub const fn checked_shr(self, s: usize) -> Option<U256>
sourcepub const fn shl1(self) -> Option<U256>
pub const fn shl1(self) -> Option<U256>
Shift left by 1. Returns None
if numerical overflow results
pub const fn checked_rotl(self, s: usize) -> Option<U256>
sourcepub fn rand_using<R>(rng: &mut R) -> U256where
R: RngCore,
pub fn rand_using<R>(rng: &mut R) -> U256where 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
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: &U256) -> bool
pub const fn const_lt(&self, rhs: &U256) -> bool
pub const fn const_le(&self, rhs: &U256) -> bool
pub const fn const_gt(&self, rhs: &U256) -> bool
pub const fn const_ge(&self, rhs: &U256) -> bool
pub const fn overflowing_short_cin_mul(self, cin: u64, rhs: u64) -> (U256, u64)
pub const fn overflowing_short_mul_add( self, lhs: U256, rhs: u64 ) -> (U256, bool)
pub const fn overflowing_mul_add(self, lhs: U256, rhs: U256) -> (U256, bool)
pub const fn checked_short_divide(self, div: u64) -> Option<(U256, u64)>
pub const fn panicking_short_divide(self, div: u64) -> (U256, u64)
pub const fn divide(self, div: U256) -> Option<(U256, U256)>
Trait Implementations§
source§impl BitAndAssign<U256> for U256
impl BitAndAssign<U256> for U256
source§fn bitand_assign(&mut self, rhs: U256)
fn bitand_assign(&mut self, rhs: U256)
&=
operation. Read moresource§impl BitOrAssign<U256> for U256
impl BitOrAssign<U256> for U256
source§fn bitor_assign(&mut self, rhs: U256)
fn bitor_assign(&mut self, rhs: U256)
|=
operation. Read moresource§impl BitXorAssign<U256> for U256
impl BitXorAssign<U256> for U256
source§fn bitxor_assign(&mut self, rhs: U256)
fn bitxor_assign(&mut self, rhs: U256)
^=
operation. Read moresource§impl<'de> Deserialize<'de> for U256
impl<'de> Deserialize<'de> for U256
source§fn deserialize<D>(
deserializer: D
) -> Result<U256, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<U256, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
Tries Deserializer::deserialize_str
and feeds it to
from_dec_or_hex_str_restricted
, else uses
Deserializer::deserialize_u64
.
source§impl Ord for U256
impl Ord for U256
source§impl PartialEq<U256> for U256
impl PartialEq<U256> for U256
source§impl PartialOrd<U256> for U256
impl PartialOrd<U256> for U256
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for U256
impl Serialize for U256
source§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
Includes a “0x” prefix.