Struct ethcontract::prelude::I256
source · pub struct I256(/* private fields */);Expand description
Little-endian 256-bit signed integer.
Implementations§
source§impl I256
impl I256
sourcepub fn from_raw(raw: U256) -> Self
pub fn from_raw(raw: U256) -> Self
Coerces an unsigned integer into a signed one. If the unsigned integer
is greater than the greater than or equal to 1 << 255, then the result
will overflow into a negative value.
sourcepub fn into_raw(self) -> U256
pub fn into_raw(self) -> U256
Returns the signed integer as a unsigned integer. If the value of self
negative, then the two’s complement of its absolute value will be
returned.
sourcepub fn as_i32(&self) -> i32
pub fn as_i32(&self) -> i32
Conversion to i32 with overflow checking
§Panics
Panics if the number is outside the range [i32::MIN, i32::MAX].
sourcepub fn as_u32(&self) -> u32
pub fn as_u32(&self) -> u32
Conversion to u32 with overflow checking
§Panics
Panics if the number is outside the range [0, u32::MAX].
sourcepub fn as_i64(&self) -> i64
pub fn as_i64(&self) -> i64
Conversion to i64 with overflow checking
§Panics
Panics if the number is outside the range [i64::MIN, i64::MAX].
sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
Conversion to u64 with overflow checking
§Panics
Panics if the number is outside the range [0, u64::MAX].
sourcepub fn as_i128(&self) -> i128
pub fn as_i128(&self) -> i128
Conversion to i128 with overflow checking
§Panics
Panics if the number is outside the range [i128::MIN, i128::MAX].
sourcepub fn as_u128(&self) -> u128
pub fn as_u128(&self) -> u128
Conversion to u128 with overflow checking
§Panics
Panics if the number is outside the range [0, u128::MAX].
sourcepub fn as_isize(&self) -> usize
pub fn as_isize(&self) -> usize
Conversion to isize with overflow checking
§Panics
Panics if the number is outside the range [isize::MIN, isize::MAX].
sourcepub fn as_usize(&self) -> usize
pub fn as_usize(&self) -> usize
Conversion to usize with overflow checking
§Panics
Panics if the number is outside the range [0, usize::MAX].
sourcepub fn from_dec_str(value: &str) -> Result<Self, ParseI256Error>
pub fn from_dec_str(value: &str) -> Result<Self, ParseI256Error>
Convert from a decimal string.
sourcepub fn from_hex_str(value: &str) -> Result<Self, ParseI256Error>
pub fn from_hex_str(value: &str) -> Result<Self, ParseI256Error>
Convert from a hexadecimal string.
sourcepub fn is_positive(self) -> bool
pub fn is_positive(self) -> bool
Returns true if self is positive and false if the number is zero
or negative.
sourcepub fn is_negative(self) -> bool
pub fn is_negative(self) -> bool
Returns true if self is negative and false if the number is zero
or negative.
sourcepub fn is_zero(self) -> bool
pub fn is_zero(self) -> bool
Returns true if self is negative and false if the number is zero
or positive.
sourcepub fn overflowing_abs(self) -> (Self, bool)
pub fn overflowing_abs(self) -> (Self, bool)
Computes the absolute value of self.
Returns a tuple of the absolute version of self along with a boolean
indicating whether an overflow happened. If self is the minimum value
(e.g., I256::MIN for values of type I256), then the minimum value
will be returned again and true will be returned for an overflow
happening.
sourcepub fn checked_abs(self) -> Option<Self>
pub fn checked_abs(self) -> Option<Self>
Checked absolute value. Computes self.abs(), returning None if
self == MIN.
sourcepub fn saturating_abs(self) -> Self
pub fn saturating_abs(self) -> Self
Saturating absolute value. Computes self.abs(), returning MAX if
self == MIN instead of overflowing.
sourcepub fn wrapping_abs(self) -> Self
pub fn wrapping_abs(self) -> Self
Wrapping absolute value. Computes self.abs(), wrapping around at the
boundary of the type.
sourcepub fn overflowing_neg(self) -> (Self, bool)
pub fn overflowing_neg(self) -> (Self, bool)
Negates self, overflowing if this is equal to the minimum value.
Returns a tuple of the negated version of self along with a boolean
indicating whether an overflow happened. If self is the minimum value,
then the minimum value will be returned again and true will be
returned for an overflow happening.
sourcepub fn checked_neg(self) -> Option<Self>
pub fn checked_neg(self) -> Option<Self>
Checked negation. Computes self.neg(), returning None if
self == MIN.
sourcepub fn saturating_neg(self) -> Self
pub fn saturating_neg(self) -> Self
Saturating negation. Computes self.neg(), returning MAX if
self == MIN instead of overflowing.
sourcepub fn wrapping_neg(self) -> Self
pub fn wrapping_neg(self) -> Self
Wrapping negation. Computes self.neg(), returning MIN if
self == MIN instead of overflowing.
sourcepub fn count_ones(&self) -> u32
pub fn count_ones(&self) -> u32
Returns the number of ones in the binary representation of self.
sourcepub fn count_zeros(&self) -> u32
pub fn count_zeros(&self) -> u32
Returns the number of zeros in the binary representation of self.
sourcepub fn leading_zeros(&self) -> u32
pub fn leading_zeros(&self) -> u32
Returns the number of leading zeros in the binary representation of
self.
sourcepub fn trailing_zeros(&self) -> u32
pub fn trailing_zeros(&self) -> u32
Returns the number of leading zeros in the binary representation of
self.
sourcepub fn to_big_endian(&self, bytes: &mut [u8])
pub fn to_big_endian(&self, bytes: &mut [u8])
Write to the slice in big-endian format.
sourcepub fn to_little_endian(&self, bytes: &mut [u8])
pub fn to_little_endian(&self, bytes: &mut [u8])
Write to the slice in little-endian format.
sourcepub fn overflowing_add(self, rhs: Self) -> (Self, bool)
pub 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.
sourcepub fn checked_add(self, other: Self) -> Option<Self>
pub fn checked_add(self, other: Self) -> Option<Self>
Checked addition. Returns None if overflow occurred.
sourcepub fn saturating_add(self, other: Self) -> Self
pub fn saturating_add(self, other: Self) -> Self
Addition which saturates at the maximum value (Self::max_value()).
sourcepub fn wrapping_add(self, other: Self) -> Self
pub fn wrapping_add(self, other: Self) -> Self
Wrapping addition.
sourcepub fn overflowing_sub(self, rhs: Self) -> (Self, bool)
pub 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.
sourcepub fn checked_sub(self, other: Self) -> Option<Self>
pub fn checked_sub(self, other: Self) -> Option<Self>
Checked subtraction. Returns None if overflow occurred.
sourcepub fn saturating_sub(self, other: Self) -> Self
pub fn saturating_sub(self, other: Self) -> Self
Subtraction which saturates at zero.
sourcepub fn wrapping_sub(self, other: Self) -> Self
pub fn wrapping_sub(self, other: Self) -> Self
Wrapping subtraction.
sourcepub fn overflowing_mul(self, rhs: Self) -> (Self, bool)
pub fn overflowing_mul(self, rhs: Self) -> (Self, bool)
Calculates self * 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.
sourcepub fn checked_mul(self, other: Self) -> Option<Self>
pub fn checked_mul(self, other: Self) -> Option<Self>
Checked multiplication. Returns None if overflow occurred.
sourcepub fn saturating_mul(self, rhs: Self) -> Self
pub fn saturating_mul(self, rhs: Self) -> Self
Multiplication which saturates at the maximum value.
sourcepub fn wrapping_mul(self, rhs: Self) -> Self
pub fn wrapping_mul(self, rhs: Self) -> Self
Wrapping multiplication.
sourcepub fn overflowing_div(self, rhs: Self) -> (Self, bool)
pub fn overflowing_div(self, rhs: Self) -> (Self, bool)
Calculates self / rhs
Returns a tuple of the division along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
sourcepub fn checked_div(self, rhs: Self) -> Option<Self>
pub fn checked_div(self, rhs: Self) -> Option<Self>
Checked division. Returns None if overflow occurred or if rhs == 0.
sourcepub fn saturating_div(self, rhs: Self) -> Self
pub fn saturating_div(self, rhs: Self) -> Self
Division which saturates at the maximum value.
sourcepub fn wrapping_div(self, rhs: Self) -> Self
pub fn wrapping_div(self, rhs: Self) -> Self
Wrapping division.
sourcepub fn overflowing_rem(self, rhs: Self) -> (Self, bool)
pub fn overflowing_rem(self, rhs: Self) -> (Self, bool)
Calculates self % rhs
Returns a tuple of the remainder along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
sourcepub fn checked_rem(self, rhs: Self) -> Option<Self>
pub fn checked_rem(self, rhs: Self) -> Option<Self>
Checked remainder. Returns None if overflow occurred or rhs == 0
sourcepub fn wrapping_rem(self, rhs: Self) -> Self
pub fn wrapping_rem(self, rhs: Self) -> Self
Wrapping remainder. Returns the result of the operation % regardless of whether or not the division overflowed.
sourcepub fn div_euclid(self, rhs: Self) -> Self
pub fn div_euclid(self, rhs: Self) -> Self
Calculates the quotient of Euclidean division of self by rhs.
This computes the integer n such that self = n * rhs + self.rem_euclid(rhs),
with 0 <= self.rem_euclid(rhs) < rhs.
In other words, the result is self / rhs rounded to the integer n such that self >= n * rhs:
- If
self > 0, this is equal to round towards zero (the default in Rust); - If
self < 0, this is equal to round towards +/- infinity.
sourcepub fn rem_euclid(self, rhs: Self) -> Self
pub fn rem_euclid(self, rhs: Self) -> Self
Calculates the least non-negative remainder of self (mod rhs).
This is done as if by the Euclidean division algorithm
given r = self.rem_euclid(rhs), self = rhs * self.div_euclid(rhs) + r, and 0 <= r < abs(rhs).
sourcepub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)
pub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)
Calculates the quotient of Euclidean division self.div_euclid(rhs).
Returns a tuple of the divisor along with a boolean indicating whether an arithmetic
overflow would occur. If an overflow would occur then self is returned.
sourcepub fn checked_div_euclid(self, rhs: Self) -> Option<Self>
pub fn checked_div_euclid(self, rhs: Self) -> Option<Self>
Checked Euclidean division. Computes self.div_euclid(rhs),
returning None if rhs == 0 or the division results in overflow.
sourcepub fn wrapping_div_euclid(self, rhs: Self) -> Self
pub fn wrapping_div_euclid(self, rhs: Self) -> Self
Wrapping Euclidean division.
Computes self.div_euclid(rhs), wrapping around at the boundary of the type.
Wrapping only occurs in MIN / -1 on a signed type
(where MIN is the negative minimal value for the type).
This is equivalent to -MIN, a positive value that is too large to represent in the type.
In this case, this method returns MIN itself.
sourcepub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool)
pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool)
Overflowing Euclidean remainder. Calculates self.rem_euclid(rhs).
Returns a tuple of the remainder after dividing along with a boolean indicating whether
an arithmetic overflow would occur. If an overflow would occur then 0 is returned.
Panics if rhs == 0
sourcepub fn wrapping_rem_euclid(self, rhs: Self) -> Self
pub fn wrapping_rem_euclid(self, rhs: Self) -> Self
Wrapping Euclidean remainder.
Computes self.rem_euclid(rhs), wrapping around at the boundary of the type.
Wrapping will only occur in MIN % -1 on a signed type
(where MIN is the negative minimal value for the type).
In this case, this method returns 0.
Panics when rhs == 0
sourcepub fn checked_rem_euclid(self, rhs: Self) -> Option<Self>
pub fn checked_rem_euclid(self, rhs: Self) -> Option<Self>
Checked Euclidean remainder. Computes self.rem_euclid(rhs),
returning None if rhs == 0 or the division results in overflow.
sourcepub fn overflowing_pow(self, exp: u32) -> (Self, bool)
pub fn overflowing_pow(self, exp: u32) -> (Self, bool)
Raises self to the power of exp.
Returns a tuple of the exponentiation along with a bool indicating whether an overflow happened.
sourcepub fn checked_pow(self, exp: u32) -> Option<Self>
pub fn checked_pow(self, exp: u32) -> Option<Self>
Raises self to the power of exp. Returns None if overflow occurred.
sourcepub fn saturating_pow(self, exp: u32) -> Self
pub fn saturating_pow(self, exp: u32) -> Self
Raises self to the power of exp, saturating at the numeric bounds
instead of overflowing.
sourcepub fn wrapping_pow(self, exp: u32) -> Self
pub fn wrapping_pow(self, exp: u32) -> Self
Wrapping powolute value. Computes self.pow(), wrapping around at the
boundary of the type.
Trait Implementations§
source§impl AddAssign for I256
impl AddAssign for I256
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl BitAndAssign for I256
impl BitAndAssign for I256
source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moresource§impl BitOrAssign for I256
impl BitOrAssign for I256
source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moresource§impl BitXorAssign for I256
impl BitXorAssign for I256
source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moresource§impl<'de> Deserialize<'de> for I256
impl<'de> Deserialize<'de> for I256
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl DivAssign for I256
impl DivAssign for I256
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moresource§impl MulAssign for I256
impl MulAssign for I256
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moresource§impl Ord for I256
impl Ord for I256
source§impl PartialEq for I256
impl PartialEq for I256
source§impl PartialOrd for I256
impl PartialOrd for I256
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 RemAssign for I256
impl RemAssign for I256
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moresource§impl ShlAssign<U256> for I256
impl ShlAssign<U256> for I256
source§fn shl_assign(&mut self, rhs: U256)
fn shl_assign(&mut self, rhs: U256)
<<= operation. Read moresource§impl ShlAssign<i128> for I256
impl ShlAssign<i128> for I256
source§fn shl_assign(&mut self, rhs: i128)
fn shl_assign(&mut self, rhs: i128)
<<= operation. Read moresource§impl ShlAssign<i16> for I256
impl ShlAssign<i16> for I256
source§fn shl_assign(&mut self, rhs: i16)
fn shl_assign(&mut self, rhs: i16)
<<= operation. Read moresource§impl ShlAssign<i32> for I256
impl ShlAssign<i32> for I256
source§fn shl_assign(&mut self, rhs: i32)
fn shl_assign(&mut self, rhs: i32)
<<= operation. Read moresource§impl ShlAssign<i64> for I256
impl ShlAssign<i64> for I256
source§fn shl_assign(&mut self, rhs: i64)
fn shl_assign(&mut self, rhs: i64)
<<= operation. Read moresource§impl ShlAssign<i8> for I256
impl ShlAssign<i8> for I256
source§fn shl_assign(&mut self, rhs: i8)
fn shl_assign(&mut self, rhs: i8)
<<= operation. Read moresource§impl ShlAssign<isize> for I256
impl ShlAssign<isize> for I256
source§fn shl_assign(&mut self, rhs: isize)
fn shl_assign(&mut self, rhs: isize)
<<= operation. Read moresource§impl ShlAssign<u128> for I256
impl ShlAssign<u128> for I256
source§fn shl_assign(&mut self, rhs: u128)
fn shl_assign(&mut self, rhs: u128)
<<= operation. Read moresource§impl ShlAssign<u16> for I256
impl ShlAssign<u16> for I256
source§fn shl_assign(&mut self, rhs: u16)
fn shl_assign(&mut self, rhs: u16)
<<= operation. Read moresource§impl ShlAssign<u32> for I256
impl ShlAssign<u32> for I256
source§fn shl_assign(&mut self, rhs: u32)
fn shl_assign(&mut self, rhs: u32)
<<= operation. Read moresource§impl ShlAssign<u64> for I256
impl ShlAssign<u64> for I256
source§fn shl_assign(&mut self, rhs: u64)
fn shl_assign(&mut self, rhs: u64)
<<= operation. Read moresource§impl ShlAssign<u8> for I256
impl ShlAssign<u8> for I256
source§fn shl_assign(&mut self, rhs: u8)
fn shl_assign(&mut self, rhs: u8)
<<= operation. Read moresource§impl ShlAssign<usize> for I256
impl ShlAssign<usize> for I256
source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<= operation. Read moresource§impl ShlAssign for I256
impl ShlAssign for I256
source§fn shl_assign(&mut self, rhs: I256)
fn shl_assign(&mut self, rhs: I256)
<<= operation. Read moresource§impl ShrAssign<U256> for I256
impl ShrAssign<U256> for I256
source§fn shr_assign(&mut self, rhs: U256)
fn shr_assign(&mut self, rhs: U256)
>>= operation. Read moresource§impl ShrAssign<i128> for I256
impl ShrAssign<i128> for I256
source§fn shr_assign(&mut self, rhs: i128)
fn shr_assign(&mut self, rhs: i128)
>>= operation. Read moresource§impl ShrAssign<i16> for I256
impl ShrAssign<i16> for I256
source§fn shr_assign(&mut self, rhs: i16)
fn shr_assign(&mut self, rhs: i16)
>>= operation. Read moresource§impl ShrAssign<i32> for I256
impl ShrAssign<i32> for I256
source§fn shr_assign(&mut self, rhs: i32)
fn shr_assign(&mut self, rhs: i32)
>>= operation. Read moresource§impl ShrAssign<i64> for I256
impl ShrAssign<i64> for I256
source§fn shr_assign(&mut self, rhs: i64)
fn shr_assign(&mut self, rhs: i64)
>>= operation. Read moresource§impl ShrAssign<i8> for I256
impl ShrAssign<i8> for I256
source§fn shr_assign(&mut self, rhs: i8)
fn shr_assign(&mut self, rhs: i8)
>>= operation. Read moresource§impl ShrAssign<isize> for I256
impl ShrAssign<isize> for I256
source§fn shr_assign(&mut self, rhs: isize)
fn shr_assign(&mut self, rhs: isize)
>>= operation. Read moresource§impl ShrAssign<u128> for I256
impl ShrAssign<u128> for I256
source§fn shr_assign(&mut self, rhs: u128)
fn shr_assign(&mut self, rhs: u128)
>>= operation. Read moresource§impl ShrAssign<u16> for I256
impl ShrAssign<u16> for I256
source§fn shr_assign(&mut self, rhs: u16)
fn shr_assign(&mut self, rhs: u16)
>>= operation. Read moresource§impl ShrAssign<u32> for I256
impl ShrAssign<u32> for I256
source§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>= operation. Read moresource§impl ShrAssign<u64> for I256
impl ShrAssign<u64> for I256
source§fn shr_assign(&mut self, rhs: u64)
fn shr_assign(&mut self, rhs: u64)
>>= operation. Read moresource§impl ShrAssign<u8> for I256
impl ShrAssign<u8> for I256
source§fn shr_assign(&mut self, rhs: u8)
fn shr_assign(&mut self, rhs: u8)
>>= operation. Read moresource§impl ShrAssign<usize> for I256
impl ShrAssign<usize> for I256
source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>= operation. Read moresource§impl ShrAssign for I256
impl ShrAssign for I256
source§fn shr_assign(&mut self, rhs: I256)
fn shr_assign(&mut self, rhs: I256)
>>= operation. Read moresource§impl SubAssign for I256
impl SubAssign for I256
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreimpl Copy for I256
impl Eq for I256
impl StructuralPartialEq for I256
Auto Trait Implementations§
impl Freeze for I256
impl RefUnwindSafe for I256
impl Send for I256
impl Sync for I256
impl Unpin for I256
impl UnwindSafe for I256
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.