u256

Struct u256 

Source
pub struct u256 { /* private fields */ }
Expand description

Implementations§

Source§

impl u256

§C3 (Constants, Constructors, Casts)

Source

pub const BITS: u32 = 256u32

The size of this integer type in bits.

§Examples
assert_eq!(u256::BITS, 256);
Source

pub const ZERO: Self

The additive identity.

§Examples
assert_eq!(x.add(u256::ZERO), x);
assert_eq!(u256::ZERO.add(x), x);
Source

pub const ONE: Self

The multiplicative identity.

§Examples
assert_eq!(x.mul(u256::ONE), x);
assert_eq!(u256::ONE.mul(x), x);
Source

pub const MIN: Self

The smallest value that can be represented by this integer type.

§Examples

Basic usage:

let min = u256::from_str_or_panic("0");
assert_eq!(u256::MIN, min);
Source

pub const MAX: Self

The largest value that can be represented by this integer type, 2256 − 1.

§Examples

Basic usage:

let max = u256::from_str_or_panic("115792089237316195423570985008687907853269984665640564039457584007913129639935");
assert_eq!(u256::MAX, max);
Source

pub const fn from_inner(inner: [u64; 4]) -> Self

Constructs an integer from its inner representation, which is a low-ordered array of words. The first element of the array corresponds to the lowest 64 bits, the second to bits 64..128, and so on.

If a word (u64) is little endian, then the type’s endianess would also be the same, but it doesn’t hold in general case.

§Examples

Basic usage:

assert!(u256::from_inner([1, 2, 3, 4]).gt(u256::from_inner([4, 3, 2, 1])));
Source

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

Returns inner representation of self.

This function is an inverse of from_inner.

§Examples

Basic usage:

let swapped = u256::from_inner([1, 2, 3, 4]).swap_words();
assert_eq!(swapped.into_inner(), [4, 3, 2, 1]);
Source

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

Constructs u256 from u8, without the loss of precision.

§Examples

Basic usage:

assert!(u256::from_u8(u8::MAX).lt(u256::MAX));
Source

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

Constructs u256 from u16, without the loss of precision.

§Examples

Basic usage:

assert!(u256::from_u16(u16::MAX).lt(u256::MAX));
Source

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

Constructs u256 from u32, without the loss of precision.

§Examples

Basic usage:

assert!(u256::from_u32(u32::MAX).lt(u256::MAX));
Source

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

Constructs u256 from u64, without the loss of precision.

§Examples

Basic usage:

assert!(u256::from_u64(u64::MAX).lt(u256::MAX));
Source

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

Constructs u256 from u128, without the loss of precision.

§Examples

Basic usage:

assert!(u256::from_u128(u128::MAX).lt(u256::MAX));
Source

pub const fn into_u384(self) -> u384

Converts self to u384, without the loss of precision.

§Examples

Basic usage:

assert!(u256::MAX.into_u384().lt(u384::MAX));
Source

pub const fn into_u512(self) -> u512

Converts self to u512, without the loss of precision.

§Examples

Basic usage:

assert!(u256::MAX.into_u512().lt(u512::MAX));
Source

pub const fn as_u8(self) -> u8

Casts self to u8 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert_eq!(u256::MAX.as_u8(), u8::MAX);
Source

pub const fn as_u16(self) -> u16

Casts self to u16 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert_eq!(u256::MAX.as_u16(), u16::MAX);
Source

pub const fn as_u32(self) -> u32

Casts self to u32 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert_eq!(u256::MAX.as_u32(), u32::MAX);
Source

pub const fn as_u64(self) -> u64

Casts self to u64 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert_eq!(u256::MAX.as_u64(), u64::MAX);
Source

pub const fn as_u128(self) -> u128

Casts self to u128 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert_eq!(u256::MAX.as_u128(), u128::MAX);
Source

pub const fn as_u256(self) -> u256

Casts self to u256 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert_eq!(u256::MAX.as_u256(), u256::MAX);
Source

pub const fn as_u384(self) -> u384

Casts self to u384 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert!(u256::MAX.as_u384().lt(u384::MAX));
Source

pub const fn as_u512(self) -> u512

Casts self to u512 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert!(u256::MAX.as_u512().lt(u512::MAX));
Source

pub const fn as_i256(self) -> i256

Casts self to i256 based on semantics explained in The Rust Reference.

§Examples

Basic usage:

assert_eq!(u256::MAX.as_i256(), i256::MINUS_ONE);
Source

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

Converts a string slice in a given base to an integer.

The string is expected to be an optional + sign followed by digits. Leading and trailing whitespace represent an error. Digits are a subset of these characters, depending on radix:

  • 0-9
  • a-z
  • A-Z
§Panics

This function panics if radix is not in the range from 2 to 36.

§Examples

Basic usage:

assert_eq!(u256::from_str_radix("A", 16), Ok(u256::from_u64(10)));
Source

pub const fn from_str_radix_or_panic(src: &str, radix: u32) -> Self

Converts a string slice in a given base to an integer.

This is the panicking variant of from_str_radix.

§Panics

This function panics if radix is not in the range from 2 to 36, or in case of a parse error due to malformed input.

§Examples

Basic usage:

assert_eq!(u256::from_str_radix_or_panic("A", 16), u256::from_u64(10));
let _ = u256::from_str_radix_or_panic("-B", 16);
Source

pub const fn from_str(src: &str) -> Result<Self, ParseIntError>

Converts a string slice in a base 10 to an integer.

§Examples

Basic usage:

assert_eq!(u256::from_str("98765432109876543210"), Ok(u256::from_u128(98765432109876543210)));
Source

pub const fn from_str_or_panic(src: &str) -> Self

Converts a string slice in a base 10 to an integer.

§Panics

This function panics whenever u256::from_str would have returned an Err.

§Examples

Basic usage:

assert_eq!(u256::from_str_or_panic("98765432109876543210"), u256::from_u128(98765432109876543210));
let _ = u256::from_str_or_panic("a");
Source

pub const fn from_hex_str(src: &str) -> Result<Self, ParseIntError>

Converts a string slice in a base 16 to an integer.

§Examples

Basic usage:

assert_eq!(u256::from_hex_str("98765432109876543210"), Ok(u256::from_u128(0x98765432109876543210)));
Source

pub const fn from_hex_str_or_panic(src: &str) -> Self

Converts a string slice in a base 16 to an integer.

§Panics

This function panics whenever u256::from_hex_str would have returned an Err.

§Examples

Basic usage:

assert_eq!(u256::from_hex_str_or_panic("98765432109876543210"), u256::from_u128(0x98765432109876543210));
let _ = u256::from_hex_str_or_panic("");
Source§

impl u256

§Equality and comparison

Source

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

Tests if self == other.

§Examples

Basic usage:

let (x, y) = (u256::ZERO, u256::ONE);
 
assert!(x.equals(x));
assert!(!x.equals(y));
Source

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

Returns an Ordering between self and other.

An implementation of a total comparison otherwise known as Ord.

§Examples

Basic usage:

use core::cmp::Ordering;
let (x, y) = (u256::ZERO, u256::ONE);
 
assert_eq!(x.compare(y), Ordering::Less);
assert_eq!(y.compare(y), Ordering::Equal);
assert_eq!(y.compare(x), Ordering::Greater);
Source

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

Shorthand for self.compare(other).is_lt().

§Examples

Basic usage:

let (x, y) = (u256::ZERO, u256::ONE);
 
assert!(x.lt(y));
Source

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

Shorthand for self.compare(other).is_gt().

§Examples

Basic usage:

let (x, y) = (u256::ZERO, u256::ONE);
 
assert!(y.gt(x));
Source

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

Shorthand for self.compare(other).is_le().

§Examples

Basic usage:

let (x, y) = (u256::ZERO, u256::ONE);
 
assert!(x.le(y));
assert!(y.le(y));
assert!(!y.le(x));
Source

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

Shorthand for self.compare(other).is_ge().

§Examples

Basic usage:

let (x, y) = (u256::ZERO, u256::ONE);
 
assert!(!x.ge(y));
assert!(y.ge(y));
assert!(y.ge(x));
Source§

impl u256

§Basic arithmetic operations

Source

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

Calculates self + rhs.

Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(5).overflowing_add(uint(2)), (uint(7), false));
assert_eq!(u256::MAX.overflowing_add(uint(1)), (uint(0), true));
Source

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

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(u256::MAX.sub(uint(2)).checked_add(uint(1)), Some(u256::MAX.sub(uint(1))));
assert_eq!(u256::MAX.sub(uint(2)).checked_add(uint(3)), None);
Source

pub const fn saturating_add(self, rhs: Self) -> Self

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(100).saturating_add(uint(1)), uint(101));
assert_eq!(u256::MAX.saturating_add(uint(127)), u256::MAX);
Source

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

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(200).wrapping_add(uint(55)), uint(255));
assert_eq!(uint(200).wrapping_add(u256::MAX), uint(199));
Source

pub const fn add(self, rhs: Self) -> Self

Calculates self + rhs.

§Overflow behavior

This function panics on overflow in debug mode and wraps around the type boundary in release mode.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(1).add(uint(1)), uint(2));
Source

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

Calculates self - rhs.

Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(5).overflowing_sub(uint(2)), (uint(3), false));
assert_eq!(uint(0).overflowing_sub(uint(1)), (u256::MAX, true));
Source

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

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(1).checked_sub(uint(1)), Some(uint(0)));
assert_eq!(uint(0).checked_sub(uint(1)), None);
Source

pub const fn saturating_sub(self, rhs: Self) -> Self

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(100).saturating_sub(uint(27)), uint(73));
assert_eq!(uint(13).saturating_sub(uint(127)), uint(0));
Source

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

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(100).wrapping_sub(uint(100)), uint(0));
assert_eq!(uint(100).wrapping_sub(u256::MAX), uint(101));
Source

pub const fn sub(self, rhs: Self) -> Self

Calculates self - rhs.

§Overflow behavior

This function panics on overflow in debug mode and wraps around the type boundary in release mode.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(629).sub(uint(81)), uint(548));
Source

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

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with u64 containing the high-order (overflowing) bits. If an overflow would have occurred then the high-order bits would contain a value not equal to 0 and the wrapped value is returned.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(5).overflowing_short_mul(2), (uint(10), 0));
assert_eq!(u256::MAX.overflowing_short_mul(10), (u256::MAX.sub(uint(9)), 9));
Source

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

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(5).checked_short_mul(1), Some(uint(5)));
assert_eq!(u256::MAX.checked_short_mul(2), None);
Source

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

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(2).saturating_short_mul(10), uint(20));
assert_eq!(u256::MAX.saturating_short_mul(10), u256::MAX);
Source

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

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(5).wrapping_short_mul(5), uint(25));
assert_eq!(u256::MAX.wrapping_short_mul(2), u256::MAX.sub(uint(1)));
Source

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

Calculates the multiplication of self and rhs.

§Overflow behavior

This function panics on overflow in debug mode and wraps around the type boundary in release mode.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(91).short_mul(10_000_000), uint(910_000_000));
Source

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

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(5).overflowing_mul(uint(2)), (uint(10), false));
assert_eq!(u256::MAX.overflowing_mul(uint(10)), (u256::MAX.sub(uint(9)), true));
Source

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

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(5).checked_mul(uint(1)), Some(uint(5)));
assert_eq!(u256::MAX.checked_mul(uint(2)), None);
Source

pub const fn saturating_mul(self, rhs: Self) -> Self

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(2).saturating_mul(uint(10)), uint(20));
assert_eq!(u256::MAX.saturating_mul(uint(10)), u256::MAX);
Source

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

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(5).wrapping_mul(uint(5)), uint(25));
assert_eq!(u256::MAX.wrapping_mul(u256::MAX), uint(1));
Source

pub const fn mul(self, rhs: Self) -> Self

Calculates the multiplication of self and rhs.

§Overflow behavior

This function panics on overflow in debug mode and wraps around the type boundary in release mode.

§Examples

Basic usage:

let uint = u256::from_u64;
assert_eq!(uint(91).mul(uint(10_000_000)), uint(910_000_000));
Source

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

Checked integer division. Computes self / rhs, returning None if rhs == 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(128).checked_short_div(2), Some(uint(64)));
assert_eq!(uint(1).checked_short_div(0), None);
Source

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

Calculates the division of self and rhs.

§Panics

This function will panic if rhs is 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(128).short_div(2), uint(64));
let _ = u256::ONE.short_div(0);
Source

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

Checked integer division. Computes self / rhs, returning None if rhs == 0.

§Examples

Basic usage:

let uint = u256::from_u64;
let y = u256::MAX;
let x = y.clear_bit(u256::BITS - 1);
 
assert_eq!(y.checked_div(x), Some(uint(2)));
assert_eq!(y.checked_div(uint(0)), None);
Source

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

Calculates the division of self and rhs.

§Panics

This function will panic if rhs is 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(8).div(uint(3)), uint(2));
let _ = u256::ONE.div(u256::ZERO);
Source

pub const fn checked_short_rem(self, rhs: u64) -> Option<u64>

Checked integer remainder. Computes self % rhs, returning None if rhs == 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(128).checked_short_rem(2), Some(0));
assert_eq!(uint(1).checked_short_rem(0), None);
Source

pub const fn short_rem(self, rhs: u64) -> u64

Calculates the remainder of self and rhs.

§Panics

This function will panic if rhs is 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(128).short_rem(2), 0);
let _ = u256::ONE.short_rem(0);
Source

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

Checked integer remainder. Computes self % rhs, returning None if rhs == 0.

§Examples

Basic usage:

let uint = u256::from_u64;
let y = u256::MAX;
let x = y.clear_bit(u256::BITS - 1);
 
assert_eq!(y.checked_rem(x), Some(uint(1)));
assert_eq!(y.checked_rem(uint(0)), None);
Source

pub const fn rem(self, rhs: Self) -> Self

Calculates the remainder of self and rhs.

§Panics

This function will panic if rhs is 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(8).rem(uint(3)), uint(2));
let _ = u256::ONE.rem(u256::ZERO);
Source§

impl u256

§Extended arithmetic operations

Source

pub const fn overflowing_neg(self) -> (Self, bool)

Negates self in an overflowing fashion.

Returns !self + 1 using wrapping operations to return the value that represents the negation of this unsigned value. Note that for positive unsigned values overflow always occurs, but negating 0 does not overflow.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0).overflowing_neg(), (uint(0), false));
assert_eq!(uint(2).overflowing_neg(), (uint(2).not().add(uint(1)), true));
Source

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

Checked negation. Computes -self, returning None unless self == 0.

Note that negating any positive integer will overflow.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0).checked_neg(), Some(uint(0)));
assert_eq!(uint(1).checked_neg(), None);
Source

pub const fn wrapping_neg(self) -> Self

Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type.

Since unsigned types do not have negative equivalents, all applications of this function will wrap (except for -0).

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0).wrapping_neg(), uint(0));
assert_eq!(uint(2).wrapping_neg(), uint(0).wrapping_sub(uint(2)));
Source

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

Computes the absolute difference between self and other.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(100).abs_diff(uint(80)), uint(20));
assert_eq!(uint(100).abs_diff(uint(110)), uint(10));
Source

pub const fn full_mul(self, rhs: Self) -> (Self, Self)

Calculates the complete product self * rhs without the possibility to overflow.

This returns the low-order (wrapping) bits and the high-order (overflow) bits of the result as two separate values, in that order.

§Examples

Basic usage:

assert_eq!(u256::MAX.full_mul(u256::MAX), (u256::ONE, u256::MAX.sub(u256::ONE)));
Source

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

Checked integer division and remainder. Computes self.short_divrem(rhs), returning None if rhs == 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(128).checked_short_divrem(2), Some((uint(64), 0)));
assert_eq!(uint(1).checked_short_divrem(0), None);
Source

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

Calculates the division and remainder of self and rhs. Slightly more efficient variant of (self.div(rhs), self.rem(rhs)) provided for convenience.

§Panics

This function will panic if rhs is 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(128).short_divrem(2), (uint(64), 0));
let _ = u256::ONE.short_divrem(0);
Source

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

Checked integer division and remainder. Computes self.divrem(rhs), returning None if rhs == 0.

§Examples

Basic usage:

let uint = u256::from_u64;
let y = u256::MAX;
let x = y.clear_bit(u256::BITS - 1);
 
assert_eq!(y.checked_divrem(x), Some((uint(2), uint(1))));
assert_eq!(y.checked_divrem(uint(0)), None);
Source

pub const fn divrem(self, rhs: Self) -> (Self, Self)

Calculates the division and remainder of self and rhs. Slightly more efficient variant of (self.div(rhs), self.rem(rhs)) provided for convenience.

§Panics

This function will panic if rhs is 0.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(8).divrem(uint(3)), (uint(2), uint(2)));
let _ = u256::ONE.divrem(u256::ZERO);
Source

pub const fn overflowing_pow(self, exp: u32) -> (Self, bool)

Raises self to the power of exp, using exponentiation by squaring.

Returns a tuple of the exponentiation along with a bool indicating whether an overflow happened.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(3).overflowing_pow(5), (uint(243), false));
assert_eq!(uint(2).overflowing_pow(512), (uint(0), true));
Source

pub const fn checked_pow(self, exp: u32) -> Option<Self>

Checked exponentiation. Computes self.pow(exp), returning None if overflow occurred.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(2).checked_pow(5), Some(uint(32)));
assert_eq!(u256::MAX.checked_pow(2), None);
Source

pub const fn saturating_pow(self, exp: u32) -> Self

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(4).saturating_pow(3), uint(64));
assert_eq!(uint(3).saturating_pow(324), u256::MAX);
Source

pub const fn wrapping_pow(self, exp: u32) -> Self

Wrapping (modular) exponentiation. Computes self.pow(exp), wrapping around at the boundary of the type.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(3).wrapping_pow(5), uint(243));
assert_eq!(uint(2).wrapping_pow(512), uint(0));
Source

pub const fn pow(self, exp: u32) -> Self

Raises self to the power of exp, using exponentiation by squaring.

§Overflow behavior

This function panics on overflow in debug mode and wraps around the type boundary in release mode.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(9).pow(9), uint(387_420_489));
Source

pub const fn overflowing_next_power_of_two(self) -> (Self, bool)

Returns the tuple pair of smallest power of two greater than or equal to self along with a bool indicating whether an overflow happened. If the next power of two is greater than the type’s maximum value, the return value is wrapped to 0.

§Examples

Basic usage:

let uint = u256::from_u64;

assert_eq!(uint(2).overflowing_next_power_of_two(), (uint(2), false));
assert_eq!(uint(3).overflowing_next_power_of_two(), (uint(4), false));
assert_eq!(u256::MAX.overflowing_next_power_of_two(), (uint(0), true));
Source

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

Returns the smallest power of two greater than or equal to self. If the next power of two is greater than the type’s maximum value, None is returned, otherwise the power of two is wrapped in Some.

§Examples

Basic usage:

let uint = u256::from_u64;

assert_eq!(uint(2).checked_next_power_of_two(), Some(uint(2)));
assert_eq!(uint(3).checked_next_power_of_two(), Some(uint(4)));
assert_eq!(u256::MAX.checked_next_power_of_two(), None);
Source

pub const fn wrapping_next_power_of_two(self) -> Self

Returns the smallest power of two greater than or equal to self. If the next power of two is greater than the type’s maximum value, the return value is wrapped to 0.

§Examples

Basic usage:

let uint = u256::from_u64;

assert_eq!(uint(2).wrapping_next_power_of_two(), uint(2));
assert_eq!(uint(3).wrapping_next_power_of_two(), uint(4));
assert_eq!(u256::MAX.wrapping_next_power_of_two(), uint(0));
Source

pub const fn next_power_of_two(self) -> Self

Returns the smallest power of two greater than or equal to self.

When return value overflows (i.e., self > (1 << (N-1)) for type uN), it panics in debug mode and the return value is wrapped to 0 in release mode (the only situation in which method can return 0).

§Examples

Basic usage:

let uint = u256::from_u64;

assert_eq!(uint(0).next_power_of_two(), uint(1));
assert_eq!(uint(1).next_power_of_two(), uint(1));
assert_eq!(uint(2).next_power_of_two(), uint(2));
assert_eq!(uint(3).next_power_of_two(), uint(4));
Source§

impl u256

§Bit manipulation

Source

pub const fn bit(self, bit: u32) -> bool

Returns the state of ith bit.

§Panics

This function panics if bit >= Self::BITS.

§Examples

Basic usage:

let uint = u256::from_u64;

assert_eq!(uint(0b011001).bit(4), true);
assert_eq!(uint(0b011001).bit(5), false);
Source

pub const fn clear_bit(self, bit: u32) -> Self

Returns the integer based of off self but with the ith bit set to 0.

§Panics

This function panics if bit >= Self::BITS.

§Examples

Basic usage:

let uint = u256::from_u64;

assert_eq!(uint(0b011001).clear_bit(4), uint(0b001001));
assert_eq!(uint(0b011001).clear_bit(5), uint(0b011001));
Source

pub const fn toggle_bit(self, bit: u32) -> Self

Flips the ith bit of self.

§Panics

This function panics if bit >= Self::BITS.

§Examples

Basic usage:

let uint = u256::from_u64;

assert_eq!(uint(0b011001).toggle_bit(4), uint(0b001001));
assert_eq!(uint(0b011001).toggle_bit(5), uint(0b111001));
Source

pub const fn set_bit(self, bit: u32) -> Self

Returns the integer based of off self but with the ith bit set to 1.

§Panics

This function panics if bit >= Self::BITS.

§Examples

Basic usage:

let uint = u256::from_u64;

assert_eq!(uint(0b011001).set_bit(4), uint(0b011001));
assert_eq!(uint(0b011001).set_bit(5), uint(0b111001));
Source

pub const fn not(self) -> Self

Flips each bit of self.

§Examples

Basic usage:

let x = u256::from_u64(0b011001).not();

assert!(!x.bit(0) && !x.bit(3) && !x.bit(4));
assert!(x.bit(1) && x.bit(2) && (5..u256::BITS).all(|i| x.bit(i)));
Source

pub const fn bitand(self, rhs: Self) -> Self

Computes bitwise and between self and rhs.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0b011001).bitand(uint(0b110011)), uint(0b010001));
Source

pub const fn bitor(self, rhs: Self) -> Self

Computes bitwise or between self and rhs.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0b011001).bitor(uint(0b110011)), uint(0b111011));
Source

pub const fn bitxor(self, rhs: Self) -> Self

Computes bitwise exclusive or between self and rhs.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0b011001).bitxor(uint(0b110011)), uint(0b101010));
Source

pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)

Shifts self left by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0x1).overflowing_shl(4), (uint(0x10), false));
assert_eq!(uint(0x1).overflowing_shl(1540), (uint(0x10), true));
Source

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

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0x1).checked_shl(4), Some(uint(0x10)));
assert_eq!(uint(0x1).checked_shl(256), None);
Source

pub const fn saturating_shl(self, rhs: u32) -> Self

Saturating shift left. Computes self << rhs, returning 0 if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0x1).saturating_shl(4), uint(0x10));
assert_eq!(uint(0x1).saturating_shl(256), uint(0));
Source

pub const fn wrapping_shl(self, rhs: u32) -> Self

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-left; the RHS of a wrapping shift-left is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. The wider integer types all implement a rotate_left function, which may be what you want instead.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(1).wrapping_shl(7), uint(128));
assert_eq!(uint(1).wrapping_shl(1536), uint(1));
Source

pub const fn shl(self, rhs: u32) -> Self

Shifts self left by rhs bits.

§Overflow behavior

This function panics on overflow in debug mode and wraps around the type boundary in release mode.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0x1).shl(4), uint(0x10));
Source

pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)

Shifts self right by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0x10).overflowing_shr(4), (uint(0x1), false));
assert_eq!(uint(0x10).overflowing_shr(1540), (uint(0x1), true));
Source

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

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0x10).checked_shr(4), Some(uint(0x1)));
assert_eq!(uint(0x10).checked_shr(256), None);
Source

pub const fn saturating_shr(self, rhs: u32) -> Self

Saturating shift right. Computes self >> rhs, returning 0 if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0x10).saturating_shr(4), uint(0x1));
assert_eq!(uint(0x10).saturating_shl(256), uint(0));
Source

pub const fn wrapping_shr(self, rhs: u32) -> Self

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-right; the RHS of a wrapping shift-right is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. The wider integer types all implement a rotate_right function, which may be what you want instead.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(128).wrapping_shr(7), uint(1));
assert_eq!(uint(128).wrapping_shr(1536), uint(128));
Source

pub const fn shr(self, rhs: u32) -> Self

Shifts self right by rhs bits.

§Overflow behavior

This function panics on overflow in debug mode and wraps around the type boundary in release mode.

§Examples

Basic usage:

let uint = u256::from_u64;
 
assert_eq!(uint(0x10).shr(4), uint(0x1));
Source

pub const fn count_ones(self) -> u32

Returns the number of ones in the binary representation of self.

§Examples

Basic usage:

let n = u256::from_u64(0b01001100);
 
assert_eq!(n.count_ones(), 3);
Source

pub const fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation of self.

§Examples

Basic usage:

assert_eq!(u256::MAX.count_zeros(), 0);
Source

pub const fn leading_ones(self) -> u32

Returns the number of leading ones in the binary representation of self.

§Examples

Basic usage:

let n = u256::MAX.shr(2).not();
 
assert_eq!(n.leading_ones(), 2);
Source

pub const fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation of self.

§Examples

Basic usage:

let n = u256::MAX.shr(2);
 
assert_eq!(n.leading_zeros(), 2);
Source

pub const fn trailing_ones(self) -> u32

Returns the number of trailing ones in the binary representation of self.

§Examples

Basic usage:

let n = u256::from_u64(0b1010111);
 
assert_eq!(n.trailing_ones(), 3);
Source

pub const fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of self.

§Examples

Basic usage:

let n = u256::from_u64(0b0101000);
 
assert_eq!(n.trailing_zeros(), 3);
Source

pub const fn rotate_left(self, rhs: u32) -> Self

Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer.

Please note this isn’t the same operation as the << shifting operator!

§Examples

Basic usage:

let n = u256::from_inner([2, 3, 0, 1]);
let m = u256::from_inner([2, 4, 6, 0]);
 
assert_eq!(n.rotate_left(65), m);
Source

pub const fn rotate_right(self, rhs: u32) -> Self

Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer.

Please note this isn’t the same operation as the >> shifting operator!

§Examples

Basic usage:

let n = u256::from_inner([2, 4, 6, 0]);
let m = u256::from_inner([2, 3, 0, 1]);
 
assert_eq!(n.rotate_right(65), m);
Source

pub const fn swap_words(self) -> Self

Reverses the word order of the integer. Here ‘word’ means an underlying primitive integer type that the current implementation relies upon. It effectively reverses the array of words returned by into_inner.

§Examples

Basic usage:

let n = u256::from_inner([1, 2, 3, 4]);
let m = u256::from_inner([4, 3, 2, 1]);
 
assert_eq!(n.swap_words(), m);
Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

§Examples

Basic usage:

let n = u256::from_hex_str_or_panic("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20");
let m = u256::from_hex_str_or_panic("201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201");
 
assert_eq!(n.swap_bytes(), m);
Source

pub const fn reverse_bits(self) -> Self

Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.

§Examples

Basic usage:

let n = u256::from_hex_str_or_panic("1234567890123456789012345678901234567890123456789012345678901234");
let m = u256::from_hex_str_or_panic("2c48091e6a2c48091e6a2c48091e6a2c48091e6a2c48091e6a2c48091e6a2c48");
 
assert_eq!(n.reverse_bits(), m);

Trait Implementations§

Source§

impl Add<&u256> for u256

Source§

type Output = u256

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &u256) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<u256> for &u256

Source§

type Output = u256

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u256) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for &u256

Source§

type Output = u256

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for u256

Source§

type Output = u256

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign<&u256> for u256

Source§

fn add_assign(&mut self, rhs: &u256)

Performs the += operation. Read more
Source§

impl AddAssign for u256

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Binary for u256

Source§

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

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

impl BitAnd<&u256> for u256

Source§

type Output = u256

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAnd<u256> for &u256

Source§

type Output = u256

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
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 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<&u256> for u256

Source§

fn bitand_assign(&mut self, rhs: &Self)

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<&u256> for u256

Source§

type Output = u256

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr<u256> for &u256

Source§

type Output = u256

The resulting type after applying the | operator.
Source§

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

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 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<&u256> for u256

Source§

fn bitor_assign(&mut self, rhs: &Self)

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<&u256> for u256

Source§

type Output = u256

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXor<u256> for &u256

Source§

type Output = u256

The resulting type after applying the ^ operator.
Source§

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

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 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<&u256> for u256

Source§

fn bitxor_assign(&mut self, rhs: &Self)

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

Source§

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

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

impl DecStr for u256

Available on crate feature serde only.
Source§

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

Source§

fn deserialize<'de, D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Source§

impl Default for u256

Source§

fn default() -> u256

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

impl DefaultModule for u256

Available on crate feature serde only.
Source§

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

Source§

fn deserialize<'de, D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Source§

impl<'de> Deserialize<'de> for u256

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for u256

Source§

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

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

impl Div<&u256> for u256

Source§

type Output = u256

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &u256) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&u64> for &u256

Source§

type Output = u256

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &u64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&u64> for u256

Source§

type Output = u256

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &u64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<u256> for &u256

Source§

type Output = u256

The resulting type after applying the / operator.
Source§

fn div(self, rhs: u256) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<u64> for &u256

Source§

type Output = u256

The resulting type after applying the / operator.
Source§

fn div(self, rhs: u64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<u64> for u256

Source§

type Output = u256

The resulting type after applying the / operator.
Source§

fn div(self, rhs: u64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for &u256

Source§

type Output = u256

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div for u256

Source§

type Output = u256

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl DivAssign<&u256> for u256

Source§

fn div_assign(&mut self, rhs: &u256)

Performs the /= operation. Read more
Source§

impl DivAssign<&u64> for u256

Source§

fn div_assign(&mut self, rhs: &u64)

Performs the /= operation. Read more
Source§

impl DivAssign<u64> for u256

Source§

fn div_assign(&mut self, rhs: u64)

Performs the /= operation. Read more
Source§

impl DivAssign for u256

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl From<u128> for u256

Source§

fn from(n: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for u256

Source§

fn from(n: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u256> for i384

Source§

fn from(n: u256) -> Self

Converts to this type from the input type.
Source§

impl From<u256> for i512

Source§

fn from(n: u256) -> Self

Converts to this type from the input type.
Source§

impl From<u256> for u384

Source§

fn from(n: u256) -> Self

Converts to this type from the input type.
Source§

impl From<u256> for u512

Source§

fn from(n: u256) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for u256

Source§

fn from(n: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for u256

Source§

fn from(n: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for u256

Source§

fn from(n: u8) -> Self

Converts to this type from the input type.
Source§

impl FromStr for u256

Source§

type Err = ParseIntError

The associated error which can be returned from parsing.
Source§

fn from_str(src: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. 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<const SIGN_AWARE: bool, const UPPER_HEX: bool, const STRICT: bool> HexStr<SIGN_AWARE, UPPER_HEX, STRICT> for u256

Available on crate feature serde only.
Source§

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

Source§

fn deserialize<'de, D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Source§

impl InnerArray for u256

Available on crate feature serde only.
Source§

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

Source§

fn deserialize<'de, D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Source§

impl LowerHex for u256

Source§

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

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

impl Mul<&u256> for u256

Source§

type Output = u256

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &u256) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&u64> for &u256

Source§

type Output = u256

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &u64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&u64> for u256

Source§

type Output = u256

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &u64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<u256> for &u256

Source§

type Output = u256

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: u256) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<u64> for &u256

Source§

type Output = u256

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: u64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<u64> for u256

Source§

type Output = u256

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: u64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for &u256

Source§

type Output = u256

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for u256

Source§

type Output = u256

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<&u256> for u256

Source§

fn mul_assign(&mut self, rhs: &u256)

Performs the *= operation. Read more
Source§

impl MulAssign<&u64> for u256

Source§

fn mul_assign(&mut self, rhs: &u64)

Performs the *= operation. Read more
Source§

impl MulAssign<u64> for u256

Source§

fn mul_assign(&mut self, rhs: u64)

Performs the *= operation. Read more
Source§

impl MulAssign for u256

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. 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 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 Octal for u256

Source§

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

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

impl Ord for u256

Source§

fn cmp(&self, other: &Self) -> 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: &Self) -> 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<'a> Product<&'a u256> for u256

Source§

fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Product for u256

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Rem<&u256> for u256

Source§

type Output = u256

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &u256) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&u64> for &u256

Source§

type Output = u64

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &u64) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&u64> for u256

Source§

type Output = u64

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &u64) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<u256> for &u256

Source§

type Output = u256

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: u256) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<u64> for &u256

Source§

type Output = u64

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: u64) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<u64> for u256

Source§

type Output = u64

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: u64) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem for &u256

Source§

type Output = u256

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl Rem for u256

Source§

type Output = u256

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl RemAssign<&u256> for u256

Source§

fn rem_assign(&mut self, rhs: &u256)

Performs the %= operation. Read more
Source§

impl RemAssign<&u64> for u256

Source§

fn rem_assign(&mut self, rhs: &u64)

Performs the %= operation. Read more
Source§

impl RemAssign<u64> for u256

Source§

fn rem_assign(&mut self, rhs: u64)

Performs the %= operation. Read more
Source§

impl RemAssign for u256

Source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
Source§

impl Serialize for u256

Available on crate feature serde only.
Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl Shl<&u32> for u256

Source§

type Output = u256

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: &u32) -> Self::Output

Performs the << operation. Read more
Source§

impl Shl<u32> for u256

Source§

type Output = u256

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: u32) -> Self::Output

Performs the << operation. Read more
Source§

impl ShlAssign<&u32> for u256

Source§

fn shl_assign(&mut self, rhs: &u32)

Performs the <<= operation. Read more
Source§

impl ShlAssign<u32> for u256

Source§

fn shl_assign(&mut self, rhs: u32)

Performs the <<= operation. Read more
Source§

impl Shr<&u32> for u256

Source§

type Output = u256

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: &u32) -> Self::Output

Performs the >> operation. Read more
Source§

impl Shr<u32> for u256

Source§

type Output = u256

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u32) -> Self::Output

Performs the >> operation. Read more
Source§

impl ShrAssign<&u32> for u256

Source§

fn shr_assign(&mut self, rhs: &u32)

Performs the >>= operation. Read more
Source§

impl ShrAssign<u32> for u256

Source§

fn shr_assign(&mut self, rhs: u32)

Performs the >>= operation. Read more
Source§

impl Sub<&u256> for u256

Source§

type Output = u256

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &u256) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<u256> for &u256

Source§

type Output = u256

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u256) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for &u256

Source§

type Output = u256

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for u256

Source§

type Output = u256

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign<&u256> for u256

Source§

fn sub_assign(&mut self, rhs: &u256)

Performs the -= operation. Read more
Source§

impl SubAssign for u256

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<'a> Sum<&'a u256> for u256

Source§

fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for u256

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl UpperHex for u256

Source§

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

Formats the value using the given formatter. Read more
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<H> HexStrDefault for H
where H: HexStr,

Source§

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

Available on crate feature serde only.
Source§

fn deserialize<'de, D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Available on crate feature serde only.
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, 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>,