pub struct Uint256(pub BUint<bnum::::types::U256::{constant#0}>);
Tuple Fields§
§0: BUint<bnum::::types::U256::{constant#0}>
Implementations§
source§impl Uint256
impl Uint256
pub fn from_le_bytes(slice: &[u8]) -> Uint256
pub fn from_be_bytes(slice: &[u8]) -> Uint256
pub fn to_be_bytes(&self) -> [u8; 32]
pub fn to_le_bytes(&self) -> [u8; 32]
Methods from Deref<Target = BUint<bnum::::types::U256::{constant#0}>>§
sourcepub fn bits(&self) -> u32
pub fn bits(&self) -> u32
Returns the smallest number of bits necessary to represent self
.
This is equal to the size of the type in bits minus the leading zeros of self
.
§Examples
use bnum::types::U256;
assert_eq!(U256::from(0b1111001010100u16).bits(), 13);
assert_eq!(U256::ZERO.bits(), 0);
sourcepub fn bit(&self, index: u32) -> bool
pub fn bit(&self, index: u32) -> bool
Returns a boolean representing the bit in the given position (true
if the bit is set). The least significant bit is at index 0
, the most significant bit is at index Self::BITS - 1
§Examples
use bnum::types::U256;
let n = U256::from(0b001010100101010101u32);
assert!(n.bit(0));
assert!(!n.bit(1));
assert!(!n.bit(U256::BITS - 1));
sourcepub fn digits(&self) -> &[u64; N]
pub fn digits(&self) -> &[u64; N]
Returns the digits stored in self
as an array. Digits are little endian (least significant digit first).
sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns whether self
is zero.
§Examples
use bnum::types::U256;
assert!(U256::ZERO.is_zero());
assert!(!U256::ONE.is_zero());
sourcepub fn is_one(&self) -> bool
pub fn is_one(&self) -> bool
Returns whether self
is one.
§Examples
use bnum::types::U256;
assert!(U256::ONE.is_one());
assert!(!U256::MAX.is_one());
pub const MIN: BUint<N> = _
pub const MAX: BUint<N> = _
pub const BITS: u32 = _
pub const BYTES: u32 = _
pub const ZERO: BUint<N> = Self::MIN
pub const ONE: BUint<N> = _
pub const TWO: BUint<N> = _
pub const THREE: BUint<N> = _
pub const FOUR: BUint<N> = _
pub const FIVE: BUint<N> = _
pub const SIX: BUint<N> = _
pub const SEVEN: BUint<N> = _
pub const EIGHT: BUint<N> = _
pub const NINE: BUint<N> = _
pub const TEN: BUint<N> = _
sourcepub fn to_str_radix(&self, radix: u32) -> String
pub fn to_str_radix(&self, radix: u32) -> String
sourcepub fn to_radix_be(&self, radix: u32) -> Vec<u8>
pub fn to_radix_be(&self, radix: u32) -> Vec<u8>
Returns the integer in the given base in big-endian digit order.
§Panics
This function panics if radix
is not in the range from 2 to 256 inclusive.
use bnum::types::U512;
let digits = &[3, 55, 60, 100, 5, 0, 5, 88];
let n = U512::from_radix_be(digits, 120).unwrap();
assert_eq!(n.to_radix_be(120), digits);
sourcepub fn to_radix_le(&self, radix: u32) -> Vec<u8>
pub fn to_radix_le(&self, radix: u32) -> Vec<u8>
Returns the integer in the given base in little-endian digit order.
§Panics
This function panics if radix
is not in the range from 2 to 256 inclusive.
use bnum::types::U512;
let digits = &[1, 67, 88, 200, 55, 68, 87, 120, 178];
let n = U512::from_radix_le(digits, 250).unwrap();
assert_eq!(n.to_radix_le(250), digits);
Trait Implementations§
source§impl AddAssign for Uint256
impl AddAssign for Uint256
source§fn add_assign(&mut self, _: Uint256)
fn add_assign(&mut self, _: Uint256)
+=
operation. Read moresource§impl CheckedAdd for Uint256
impl CheckedAdd for Uint256
source§impl CheckedDiv for Uint256
impl CheckedDiv for Uint256
source§impl CheckedMul for Uint256
impl CheckedMul for Uint256
source§impl CheckedSub for Uint256
impl CheckedSub for Uint256
source§impl<'de> Deserialize<'de> for Uint256
impl<'de> Deserialize<'de> for Uint256
source§fn deserialize<D>(
deserializer: D
) -> Result<Uint256, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<Uint256, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl DivAssign for Uint256
impl DivAssign for Uint256
source§fn div_assign(&mut self, _: Uint256)
fn div_assign(&mut self, _: Uint256)
/=
operation. Read moresource§impl FromPrimitive for Uint256
impl FromPrimitive for Uint256
source§fn from_i64(n: i64) -> Option<Uint256>
fn from_i64(n: i64) -> Option<Uint256>
i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u64(n: u64) -> Option<Uint256>
fn from_u64(n: u64) -> Option<Uint256>
u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i128(n: i128) -> Option<Uint256>
fn from_i128(n: i128) -> Option<Uint256>
i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_u128(n: u128) -> Option<Uint256>
fn from_u128(n: u128) -> Option<Uint256>
u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
u16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u32(n: u32) -> Option<Self>
fn from_u32(n: u32) -> Option<Self>
u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§impl MulAssign for Uint256
impl MulAssign for Uint256
source§fn mul_assign(&mut self, _: Uint256)
fn mul_assign(&mut self, _: Uint256)
*=
operation. Read moresource§impl Num for Uint256
impl Num for Uint256
type FromStrRadixErr = ParseError
source§impl Ord for Uint256
impl Ord for Uint256
source§impl PartialEq for Uint256
impl PartialEq for Uint256
source§impl PartialOrd for Uint256
impl PartialOrd for Uint256
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 Uint256
impl RemAssign for Uint256
source§fn rem_assign(&mut self, _: Uint256)
fn rem_assign(&mut self, _: Uint256)
%=
operation. Read moresource§impl Serialize for Uint256
impl Serialize for Uint256
source§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
source§impl ShlAssign for Uint256
impl ShlAssign for Uint256
source§fn shl_assign(&mut self, _: Uint256)
fn shl_assign(&mut self, _: Uint256)
<<=
operation. Read moresource§impl ShrAssign for Uint256
impl ShrAssign for Uint256
source§fn shr_assign(&mut self, _: Uint256)
fn shr_assign(&mut self, _: Uint256)
>>=
operation. Read moresource§impl SubAssign for Uint256
impl SubAssign for Uint256
source§fn sub_assign(&mut self, _: Uint256)
fn sub_assign(&mut self, _: Uint256)
-=
operation. Read moresource§impl ToPrimitive for Uint256
impl ToPrimitive for Uint256
source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self
to an i64
. If the value cannot be
represented by an i64
, then None
is returned.source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self
to a u64
. If the value cannot be
represented by a u64
, then None
is returned.source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self
to an i128
. If the value cannot be
represented by an i128
(i64
under the default implementation), then
None
is returned. Read moresource§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self
to a u128
. If the value cannot be
represented by a u128
(u64
under the default implementation), then
None
is returned. Read moresource§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self
to an isize
. If the value cannot be
represented by an isize
, then None
is returned.source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self
to an i8
. If the value cannot be
represented by an i8
, then None
is returned.source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self
to an i16
. If the value cannot be
represented by an i16
, then None
is returned.source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self
to an i32
. If the value cannot be
represented by an i32
, then None
is returned.source§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self
to a usize
. If the value cannot be
represented by a usize
, then None
is returned.source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self
to a u8
. If the value cannot be
represented by a u8
, then None
is returned.source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self
to a u16
. If the value cannot be
represented by a u16
, then None
is returned.source§fn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
self
to a u32
. If the value cannot be
represented by a u32
, then None
is returned.