Struct Uint

Source
#[repr(C)]
pub struct Uint<const N: usize>(/* private fields */);
Expand description

A structure that represents large integers and provides basic arithmetic. It accepts a const generic N which controls the number of u64s used to represent the number.

Implementations§

Source§

impl<const N: usize> Uint<N>

Source

pub const MAX: Self

The maximum value that can be represented by this type

Source

pub const MIN: Self

The minimum value that can be represented by this type

Source

pub fn from_u64_array(data: [u64; N]) -> Self

Build a Uint from a u64 array

Source

pub fn low_u32(&self) -> u32

Conversion to u32

Source

pub fn low_u64(&self) -> u64

Conversion to u64

Source

pub fn bits(&self) -> usize

Return the least number of bits needed to represent the number

Source

pub fn mul_u32(self, other: u32) -> Self

Multiply by a u32

Source

pub fn to_le_bytes(&self) -> Vec<u8>

To litte-endian byte array

Source

pub fn to_be_bytes(&self) -> Vec<u8>

To big-endian byte array

Source

pub fn from_le_bytes(bytes: impl AsRef<[u8]>) -> StacksResult<Self>

Build from a little-endian hex string (padding expected)

Source

pub fn from_be_bytes(bytes: impl AsRef<[u8]>) -> StacksResult<Self>

Build from a big-endian hex string (padding expected)

Source

pub fn to_le_hex(&self) -> String

Convert to a little-endian hex string

Source

pub fn to_be_hex(&self) -> String

Convert to a big-endian hex string

Source

pub fn from_le_hex(data: impl AsRef<str>) -> StacksResult<Self>

Build from a little-endian hex string

Source

pub fn from_be_hex(data: impl AsRef<str>) -> StacksResult<Self>

Build from a big-endian hex string

Source

pub fn increment(&mut self)

Wrapping add by one operation

Source

pub fn from_uint<const M: usize>(source: impl AsRef<Uint<M>>) -> Self

Create a new Uint from the provided Uint

Source

pub fn from_uint_lossy<const M: usize>(source: impl AsRef<Uint<M>>) -> Self

Create a new Uint from the provided Uint, truncating if necessary

Source

pub fn to_uint<const M: usize>(&self) -> Uint<M>

Convert to a smaller Uint

Source

pub fn to_uint_lossy<const M: usize>(&self) -> Uint<M>

Convert to a smaller Uint, truncating if necessary

Trait Implementations§

Source§

impl<const N: usize> Add for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl<const N: usize> AsRef<Uint<N>> for Uint<N>

Source§

fn as_ref(&self) -> &Uint<N>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const N: usize> BitAnd for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: Uint<N>) -> Self

Performs the & operation. Read more
Source§

impl<const N: usize> BitOr for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Uint<N>) -> Self

Performs the | operation. Read more
Source§

impl<const N: usize> BitXor for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: Uint<N>) -> Self

Performs the ^ operation. Read more
Source§

impl<const N: usize> Clone for Uint<N>

Source§

fn clone(&self) -> Uint<N>

Returns a copy 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<const N: usize> Codec for Uint<N>

Source§

fn codec_serialize<W: Write>(&self, dest: &mut W) -> Result<()>

Serialize to a writer
Source§

fn codec_deserialize<R: Read>(data: &mut R) -> Result<Self>
where Self: Sized,

Deserialize from a reader
Source§

fn serialize<W: Write>(&self, dest: &mut W) -> StacksResult<()>

Serialize to a writer and return a StacksResult
Source§

fn deserialize<R: Read>(data: &mut R) -> StacksResult<Self>
where Self: Sized,

Deserialize from a reader and return a StacksResult
Source§

fn serialize_to_vec(&self) -> Vec<u8>

Serialize to a vector
Source§

impl<const N: usize> Debug for Uint<N>

Source§

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

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

impl<const N: usize> Default for Uint<N>

Source§

fn default() -> Self

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

impl<'de, const N: usize> Deserialize<'de> for Uint<N>

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<const N: usize> Display for Uint<N>

Source§

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

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

impl<const N: usize> Div for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Self

Performs the / operation. Read more
Source§

impl<const N: usize> From<u128> for Uint<N>

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<u16> for Uint<N>

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<u32> for Uint<N>

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<u64> for Uint<N>

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<u8> for Uint<N>

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> Into<Vec<u64>> for Uint<N>

Source§

fn into(self) -> Vec<u64>

Converts this type into the (usually inferred) input type.
Source§

impl<const N: usize> Mul for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl<const N: usize> Not for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl<const N: usize> Ord for Uint<N>

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<const N: usize> PartialEq for Uint<N>

Source§

fn eq(&self, other: &Uint<N>) -> 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<const N: usize> PartialOrd for Uint<N>

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<const N: usize> Serialize for Uint<N>

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<const N: usize> Shl<usize> for Uint<N>

Source§

type Output = Uint<N>

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

fn shl(self, shift: usize) -> Self

Performs the << operation. Read more
Source§

impl<const N: usize> Shr<usize> for Uint<N>

Source§

type Output = Uint<N>

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

fn shr(self, shift: usize) -> Self

Performs the >> operation. Read more
Source§

impl<const N: usize> Sub for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl<const N: usize> TryFrom<Vec<u64>> for Uint<N>

Source§

type Error = StacksError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Vec<u64>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> Copy for Uint<N>

Source§

impl<const N: usize> Eq for Uint<N>

Source§

impl<const N: usize> StructuralPartialEq for Uint<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Uint<N>

§

impl<const N: usize> RefUnwindSafe for Uint<N>

§

impl<const N: usize> Send for Uint<N>

§

impl<const N: usize> Sync for Uint<N>

§

impl<const N: usize> Unpin for Uint<N>

§

impl<const N: usize> UnwindSafe for Uint<N>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,