U256

Struct 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; 8]) -> Self

Source

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

Source

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

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<Self, FromStrRadixErr>

Source

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

Source

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

Source

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.

Source

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

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

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<Self>

Returns 10^exp, or None if overflow occurs

Source§

impl U256

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub const fn resize_to_u8(self) -> u8

Source

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

Source

pub const fn resize_to_u16(self) -> u16

Source

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

Source

pub const fn resize_to_u32(self) -> u32

Source

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

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]) -> Self

Source

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

Source

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

Source

pub const fn resize_to_bool(self) -> bool

Source

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

Source

pub const fn resize_to_u128(self) -> u128

Source

pub const fn zero() -> Self

Source

pub const fn one() -> Self

Source

pub const fn max_value() -> Self

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Shift left by 1. Returns None if numerical overflow results

Source

pub const fn shr1(self) -> Self

Shift right by 1

Source

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

Source

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,
    ])
);
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: &Self) -> bool

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl BitAnd for U256

Source§

type Output = U256

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAndAssign for U256

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr for U256

Source§

type Output = U256

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOrAssign for U256

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitXor for U256

Source§

type Output = U256

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXorAssign for U256

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl Clone for U256

Source§

fn clone(&self) -> U256

Returns a duplicate 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

Available on non-crate feature use_parity_uint only.
Source§

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

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

impl Default for U256

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for U256

Available on crate feature serde_support only.
Source§

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.

Source§

impl Display for U256

Available on non-crate feature use_parity_uint only.
Source§

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

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

impl Hash for U256

Source§

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

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

Available on non-crate feature use_parity_uint only.
Source§

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

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

impl Not for U256

Source§

type Output = U256

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::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) -> Self
where Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for U256

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for U256

Available on crate feature serde_support only.
Source§

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

Includes a “0x” prefix.

Source§

impl Copy for U256

Source§

impl Eq for U256

Source§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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

Source§

fn to_string(&self) -> String

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

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

Source§

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

Source§

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 T
where T: for<'de> Deserialize<'de>,