pub struct Uint512(_);
Expand description
An implementation of u512 that is using strings for JSON encoding/decoding, such that the full u512 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.
Examples
Use from
to create instances out of primitive uint types or new
to provide big
endian bytes:
let a = Uint512::from(258u128);
let b = Uint512::new([
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8,
]);
assert_eq!(a, b);
Implementations§
source§impl Uint512
impl Uint512
pub const MAX: Uint512 = Uint512(U512::MAX)
pub const MIN: Uint512 = Uint512(U512::zero())
sourcepub const fn new(value: [u8; 64]) -> Uint512
pub const fn new(value: [u8; 64]) -> Uint512
Creates a Uint512(value) from a big endian representation. It’s just an alias for
from_big_endian
.
pub const fn from_be_bytes(data: [u8; 64]) -> Uint512
pub const fn from_le_bytes(data: [u8; 64]) -> Uint512
sourcepub const fn from_uint256(num: Uint256) -> Uint512
pub const fn from_uint256(num: Uint256) -> Uint512
A conversion from Uint256
that, unlike the one provided by the From
trait,
can be used in a const
context.
sourcepub const fn to_be_bytes(self) -> [u8; 64]
pub const fn to_be_bytes(self) -> [u8; 64]
Returns a copy of the number as big endian bytes.
sourcepub const fn to_le_bytes(self) -> [u8; 64]
pub const fn to_le_bytes(self) -> [u8; 64]
Returns a copy of the number as little endian bytes.
pub const fn is_zero(&self) -> bool
pub fn pow(self, exp: u32) -> Uint512
pub fn checked_add(self, other: Uint512) -> Result<Uint512, OverflowError>
pub fn checked_sub(self, other: Uint512) -> Result<Uint512, OverflowError>
pub fn checked_mul(self, other: Uint512) -> Result<Uint512, OverflowError>
pub fn checked_pow(self, exp: u32) -> Result<Uint512, OverflowError>
pub fn checked_div(self, other: Uint512) -> Result<Uint512, DivideByZeroError>
pub fn checked_div_euclid( self, other: Uint512 ) -> Result<Uint512, DivideByZeroError>
pub fn checked_rem(self, other: Uint512) -> Result<Uint512, DivideByZeroError>
pub fn checked_shr(self, other: u32) -> Result<Uint512, OverflowError>
pub fn wrapping_add(self, other: Uint512) -> Uint512
pub fn wrapping_sub(self, other: Uint512) -> Uint512
pub fn wrapping_mul(self, other: Uint512) -> Uint512
pub fn wrapping_pow(self, other: u32) -> Uint512
pub fn saturating_add(self, other: Uint512) -> Uint512
pub fn saturating_sub(self, other: Uint512) -> Uint512
pub fn saturating_mul(self, other: Uint512) -> Uint512
pub fn saturating_pow(self, exp: u32) -> Uint512
pub fn abs_diff(self, other: Uint512) -> Uint512
Trait Implementations§
source§impl<'a> AddAssign<&'a Uint512> for Uint512
impl<'a> AddAssign<&'a Uint512> for Uint512
source§fn add_assign(&mut self, rhs: &'a Uint512)
fn add_assign(&mut self, rhs: &'a Uint512)
Performs the
+=
operation. Read moresource§impl AddAssign<Uint512> for Uint512
impl AddAssign<Uint512> for Uint512
source§fn add_assign(&mut self, rhs: Uint512)
fn add_assign(&mut self, rhs: Uint512)
Performs the
+=
operation. Read moresource§impl<'de> Deserialize<'de> for Uint512
impl<'de> Deserialize<'de> for Uint512
source§fn deserialize<D>(
deserializer: D
) -> Result<Uint512, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Uint512, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
Deserialized from an integer string using base 10
source§impl<'a> DivAssign<&'a Uint512> for Uint512
impl<'a> DivAssign<&'a Uint512> for Uint512
source§fn div_assign(&mut self, rhs: &'a Uint512)
fn div_assign(&mut self, rhs: &'a Uint512)
Performs the
/=
operation. Read moresource§impl DivAssign<Uint512> for Uint512
impl DivAssign<Uint512> for Uint512
source§fn div_assign(&mut self, rhs: Uint512)
fn div_assign(&mut self, rhs: Uint512)
Performs the
/=
operation. Read moresource§impl FadromaDeserialize for Uint512
impl FadromaDeserialize for Uint512
source§fn from_bytes<'a>(de: &mut Deserializer<'a>) -> Result<Self>
fn from_bytes<'a>(de: &mut Deserializer<'a>) -> Result<Self>
Deserialize into a new instance by reading bytes from
the provided
Deserializer
.source§impl FadromaSerialize for Uint512
impl FadromaSerialize for Uint512
source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
The size in bytes of the particular instance when
converted to its byte respresentation. While it’s
preferred that this method returns an exact size
(or at least a bigger estimation) it’s not an error
to return an incorrect number. The penalty for doing
so is potentially incurring unnecessary re-allocations.
source§fn to_bytes(&self, ser: &mut Serializer) -> Result<()>
fn to_bytes(&self, ser: &mut Serializer) -> Result<()>
Serialize the instance into bytes by writing to
the provided
Serializer
.source§impl JsonSchema for Uint512
impl JsonSchema for Uint512
source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read moresource§impl MulAssign<&Uint512> for Uint512
impl MulAssign<&Uint512> for Uint512
source§fn mul_assign(&mut self, other: &Uint512)
fn mul_assign(&mut self, other: &Uint512)
Performs the
*=
operation. Read moresource§impl MulAssign<Uint512> for Uint512
impl MulAssign<Uint512> for Uint512
source§fn mul_assign(&mut self, rhs: Uint512)
fn mul_assign(&mut self, rhs: Uint512)
Performs the
*=
operation. Read moresource§impl Ord for Uint512
impl Ord for Uint512
source§impl PartialEq<&Uint512> for Uint512
impl PartialEq<&Uint512> for Uint512
source§impl PartialEq<Uint512> for &Uint512
impl PartialEq<Uint512> for &Uint512
source§impl PartialEq<Uint512> for Uint512
impl PartialEq<Uint512> for Uint512
source§impl PartialOrd<Uint512> for Uint512
impl PartialOrd<Uint512> for Uint512
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl RemAssign<&Uint512> for Uint512
impl RemAssign<&Uint512> for Uint512
source§fn rem_assign(&mut self, other: &Uint512)
fn rem_assign(&mut self, other: &Uint512)
Performs the
%=
operation. Read moresource§impl RemAssign<Uint512> for Uint512
impl RemAssign<Uint512> for Uint512
source§fn rem_assign(&mut self, rhs: Uint512)
fn rem_assign(&mut self, rhs: Uint512)
Performs the
%=
operation. Read moresource§impl Serialize for Uint512
impl Serialize for Uint512
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,
Serializes as an integer string using base 10
source§impl<'a> ShrAssign<&'a u32> for Uint512
impl<'a> ShrAssign<&'a u32> for Uint512
source§fn shr_assign(&mut self, rhs: &'a u32)
fn shr_assign(&mut self, rhs: &'a u32)
Performs the
>>=
operation. Read moresource§impl ShrAssign<u32> for Uint512
impl ShrAssign<u32> for Uint512
source§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
Performs the
>>=
operation. Read moresource§impl SubAssign<&Uint512> for Uint512
impl SubAssign<&Uint512> for Uint512
source§fn sub_assign(&mut self, other: &Uint512)
fn sub_assign(&mut self, other: &Uint512)
Performs the
-=
operation. Read moresource§impl SubAssign<Uint512> for Uint512
impl SubAssign<Uint512> for Uint512
source§fn sub_assign(&mut self, rhs: Uint512)
fn sub_assign(&mut self, rhs: Uint512)
Performs the
-=
operation. Read moreimpl Copy for Uint512
impl Eq for Uint512
impl StructuralEq for Uint512
impl StructuralPartialEq for Uint512
Auto Trait Implementations§
impl RefUnwindSafe for Uint512
impl Send for Uint512
impl Sync for Uint512
impl Unpin for Uint512
impl UnwindSafe for Uint512
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
Mutably borrows from an owned value. Read more