Struct u64_array_bigints::U256

source ·
pub struct U256(pub Uint<4>);

Tuple Fields§

§0: Uint<4>

Implementations§

source§

impl U256

source

pub fn from_usize_array(x: [usize; 4]) -> U256

source

pub fn to_usize_array(self) -> [usize; 4]

source

pub const fn from_usize(x: usize) -> U256

source

pub const fn resize_to_usize(self) -> usize

source

pub fn try_resize_to_usize(self) -> Option<usize>

source§

impl U256

source

pub fn from_hex_str_fast(src: &[u8]) -> Result<U256, FromStrRadixErr>

source

pub const fn from_bytes_radix( src: &[u8], radix: u8 ) -> Result<U256, FromStrRadixErr>

source

pub const fn from_str_radix( src: &str, radix: u8 ) -> Result<U256, FromStrRadixErr>

source

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.

source

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

source

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

source

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”

source

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

source

pub fn to_dec_string(self) -> String

source

pub const fn checked_exp10(exp: usize) -> Option<U256>

Returns 10^exp, or None if overflow occurs

source§

impl U256

source

pub fn from_u8_array(x: [u8; 32]) -> U256

source

pub fn to_u8_array(self) -> [u8; 32]

source

pub fn from_u16_array(x: [u16; 16]) -> U256

source

pub fn to_u16_array(self) -> [u16; 16]

source

pub fn from_u32_array(x: [u32; 8]) -> U256

source

pub fn to_u32_array(self) -> [u32; 8]

source

pub fn from_u128_array(x: [u128; 2]) -> U256

source

pub fn to_u128_array(self) -> [u128; 2]

source

pub const fn from_u8(x: u8) -> U256

source

pub const fn resize_to_u8(self) -> u8

source

pub const fn from_u16(x: u16) -> U256

source

pub const fn resize_to_u16(self) -> u16

source

pub const fn from_u32(x: u32) -> U256

source

pub const fn resize_to_u32(self) -> u32

source

pub const fn from_u64(x: u64) -> U256

source

pub const fn resize_to_u64(self) -> u64

source

pub const fn try_resize_to_bool(self) -> Option<bool>

source

pub const fn try_resize_to_u8(self) -> Option<u8>

source

pub const fn try_resize_to_u16(self) -> Option<u16>

source

pub const fn try_resize_to_u32(self) -> Option<u32>

source

pub const fn try_resize_to_u64(self) -> Option<u64>

source

pub const fn try_resize_to_u128(self) -> Option<u128>

source

pub const fn from_u64_array(x: [u64; 4]) -> U256

source

pub const fn to_u64_array(self) -> [u64; 4]

source

pub const fn from_bool(x: bool) -> U256

source

pub const fn resize_to_bool(self) -> bool

source

pub const fn from_u128(x: u128) -> U256

source

pub const fn resize_to_u128(self) -> u128

source

pub const fn zero() -> U256

source

pub const fn one() -> U256

source

pub const fn max_value() -> U256

source

pub const fn is_zero(self) -> bool

source

pub const fn sig_bits(self) -> usize

Significant bits

source

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

source

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

source

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

source

pub fn from_u8_array_be(x: [u8; 32]) -> U256

source

pub fn to_u8_array_be(self) -> [u8; 32]

source

pub const fn overflowing_add(self, other: U256) -> (U256, bool)

source

pub const fn overflowing_sub(self, other: U256) -> (U256, bool)

source

pub const fn overflowing_mul(self, other: U256) -> (U256, bool)

source

pub const fn wrapping_add(self, other: U256) -> U256

source

pub const fn wrapping_sub(self, other: U256) -> U256

source

pub const fn wrapping_mul(self, other: U256) -> U256

source

pub const fn wrapping_shl(self, s: usize) -> U256

source

pub const fn wrapping_shr(self, s: usize) -> U256

source

pub const fn checked_add(self, rhs: U256) -> Option<U256>

source

pub const fn checked_sub(self, rhs: U256) -> Option<U256>

source

pub const fn checked_mul(self, rhs: U256) -> Option<U256>

source

pub const fn checked_shl(self, s: usize) -> Option<U256>

source

pub const fn checked_shr(self, s: usize) -> Option<U256>

source

pub const fn shl1(self) -> Option<U256>

Shift left by 1. Returns None if numerical overflow results

source

pub const fn shr1(self) -> U256

Shift right by 1

source

pub const fn checked_rotl(self, s: usize) -> Option<U256>

source

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

These are forwarded from Uint<4>

source

pub const fn bw() -> usize

source

pub const fn lsb(&self) -> bool

source

pub const fn msb(&self) -> bool

source

pub const fn lz(&self) -> usize

source

pub const fn tz(&self) -> usize

source

pub const fn count_ones(&self) -> usize

source

pub const fn const_eq(&self, rhs: &U256) -> bool

source

pub const fn const_lt(&self, rhs: &U256) -> bool

source

pub const fn const_le(&self, rhs: &U256) -> bool

source

pub const fn const_gt(&self, rhs: &U256) -> bool

source

pub const fn const_ge(&self, rhs: &U256) -> bool

source

pub const fn overflowing_short_cin_mul(self, cin: u64, rhs: u64) -> (U256, u64)

source

pub const fn overflowing_short_mul_add( self, lhs: U256, rhs: u64 ) -> (U256, bool)

source

pub const fn overflowing_mul_add(self, lhs: U256, rhs: U256) -> (U256, bool)

source

pub const fn checked_short_divide(self, div: u64) -> Option<(U256, u64)>

source

pub const fn panicking_short_divide(self, div: u64) -> (U256, u64)

source

pub const fn divide(self, div: U256) -> Option<(U256, U256)>

Trait Implementations§

source§

impl BitAnd<U256> for U256

§

type Output = U256

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: U256) -> <U256 as BitAnd<U256>>::Output

Performs the & operation. Read more
source§

impl BitAndAssign<U256> for U256

source§

fn bitand_assign(&mut self, rhs: U256)

Performs the &= operation. Read more
source§

impl BitOr<U256> for U256

§

type Output = U256

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: U256) -> <U256 as BitOr<U256>>::Output

Performs the | operation. Read more
source§

impl BitOrAssign<U256> for U256

source§

fn bitor_assign(&mut self, rhs: U256)

Performs the |= operation. Read more
source§

impl BitXor<U256> for U256

§

type Output = U256

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: U256) -> <U256 as BitXor<U256>>::Output

Performs the ^ operation. Read more
source§

impl BitXorAssign<U256> for U256

source§

fn bitxor_assign(&mut self, rhs: U256)

Performs the ^= operation. Read more
source§

impl Clone for U256

source§

fn clone(&self) -> U256

Returns a copy 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<(), Error>

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

source§

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

source§

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

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

impl Hash for U256

source§

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

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

source§

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

Formats the value using the given formatter.
source§

impl Not for U256

§

type Output = U256

The resulting type after applying the ! operator.
source§

fn not(self) -> <U256 as Not>::Output

Performs the unary ! operation. 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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl PartialEq<U256> for U256

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<U256> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for U256

source§

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

Includes a “0x” prefix.

source§

impl Copy for U256

source§

impl Eq for U256

source§

impl StructuralEq for U256

source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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

source§

default fn to_string(&self) -> String

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

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

§

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

§

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

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