Struct sp_runtime::biguint::BigUint
source · [−]pub struct BigUint { /* private fields */ }Expand description
Simple wrapper around an infinitely large integer, represented as limbs of Single.
Implementations
sourceimpl BigUint
impl BigUint
sourcepub fn with_capacity(size: usize) -> BigUint
pub fn with_capacity(size: usize) -> BigUint
Create a new instance with size limbs. This prevents any number with zero limbs to be
created.
The behavior of the type is undefined with zero limbs.
sourcepub fn from_limbs(limbs: &[u32]) -> BigUint
pub fn from_limbs(limbs: &[u32]) -> BigUint
Raw constructor from custom limbs. If limbs is empty, Zero::zero() implementation is
used.
sourcepub fn get(&self, index: usize) -> u32
pub fn get(&self, index: usize) -> u32
A naive getter for limb at index. Note that the order is lsb -> msb.
Panics
This panics if index is out of range.
sourcepub fn checked_get(&self, index: usize) -> Option<u32>
pub fn checked_get(&self, index: usize) -> Option<u32>
A naive getter for limb at index. Note that the order is lsb -> msb.
sourcepub fn set(&mut self, index: usize, value: u32)
pub fn set(&mut self, index: usize, value: u32)
A naive setter for limb at index. Note that the order is lsb -> msb.
Panics
This panics if index is out of range.
sourcepub fn lsb(&self) -> u32
pub fn lsb(&self) -> u32
returns the least significant limb of the number.
Panics
While the constructor of the type prevents this, this can panic if self has no digits.
sourcepub fn msb(&self) -> u32
pub fn msb(&self) -> u32
returns the most significant limb of the number.
Panics
While the constructor of the type prevents this, this can panic if self has no digits.
sourcepub fn lstrip(&mut self)
pub fn lstrip(&mut self)
Strips zeros from the left side (the most significant limbs) of self, if any.
sourcepub fn lpad(&mut self, size: usize)
pub fn lpad(&mut self, size: usize)
Zero-pad self from left to reach size limbs. Will not make any difference if self
is already bigger than size limbs.
sourcepub fn add(self, other: &BigUint) -> BigUint
pub fn add(self, other: &BigUint) -> BigUint
Adds self with other. self and other do not have to have any particular size. Given
that the n = max{size(self), size(other)}, it will produce a number with n + 1
limbs.
This function does not strip the output and returns the original allocated n + 1
limbs. The caller may strip the output if desired.
Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.
sourcepub fn sub(self, other: &BigUint) -> Result<BigUint, BigUint>
pub fn sub(self, other: &BigUint) -> Result<BigUint, BigUint>
Subtracts other from self. self and other do not have to have any particular size.
Given that the n = max{size(self), size(other)}, it will produce a number of size n.
If other is bigger than self, Err(B - borrow) is returned.
Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.
sourcepub fn mul(self, other: &BigUint) -> BigUint
pub fn mul(self, other: &BigUint) -> BigUint
Multiplies n-limb number self with m-limb number other.
The resulting number will always have n + m limbs.
This function does not strip the output and returns the original allocated n + m
limbs. The caller may strip the output if desired.
Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.
sourcepub fn div_unit(self, other: u32) -> BigUint
pub fn div_unit(self, other: u32) -> BigUint
Divides self by a single limb other. This can be used in cases where the original
division cannot work due to the divisor (other) being just one limb.
Invariant: other cannot be zero.
sourcepub fn div(self, other: &BigUint, rem: bool) -> Option<(BigUint, BigUint)>
pub fn div(self, other: &BigUint, rem: bool) -> Option<(BigUint, BigUint)>
Divides an n + m limb self by a n limb other. The result is a m + 1 limb
quotient and a n limb remainder, if enabled by passing true in rem argument, both
in the form of an option’s Ok.
- requires
otherto be stripped and have no leading zeros. - requires
selfto be stripped and have no leading zeros. - requires
otherto have at least two limbs. - requires
selfto have a greater length compared toother.
All arguments are examined without being stripped for the above conditions. If any of
the above fails, None is returned.`
Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.
Trait Implementations
sourceimpl Decode for BigUint
impl Decode for BigUint
sourcepub fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy
) -> Result<BigUint, Error> where
__CodecInputEdqy: Input,
pub fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy
) -> Result<BigUint, Error> where
__CodecInputEdqy: Input,
Attempt to deserialise the value from input.
sourcefn skip<I>(input: &mut I) -> Result<(), Error> where
I: Input,
fn skip<I>(input: &mut I) -> Result<(), Error> where
I: Input,
Attempt to skip the encoded value from input. Read more
sourcefn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
Returns the fixed encoded size of the type. Read more
sourceimpl Encode for BigUint
impl Encode for BigUint
sourcepub fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy
) where
__CodecOutputEdqy: Output + ?Sized,
pub fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy
) where
__CodecOutputEdqy: Output + ?Sized,
Convert self to a slice and append it to the destination.
sourcepub fn encode(&self) -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn encode(&self) -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Convert self to an owned vector.
sourcepub fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
pub fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
Convert self to a slice and then invoke the given closure with it.
sourcefn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
sourcefn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
sourceimpl Ord for BigUint
impl Ord for BigUint
sourceimpl PartialOrd<BigUint> for BigUint
impl PartialOrd<BigUint> for BigUint
sourcepub fn partial_cmp(&self, other: &BigUint) -> Option<Ordering>
pub fn partial_cmp(&self, other: &BigUint) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn 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 more
impl EncodeLike<BigUint> for BigUint
impl Eq for BigUint
Auto Trait Implementations
impl RefUnwindSafe for BigUint
impl Send for BigUint
impl Sync for BigUint
impl Unpin for BigUint
impl UnwindSafe for BigUint
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedConversion for T
impl<T> CheckedConversion for T
sourcefn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
Convert from a value of T into an equivalent instance of Option<Self>. Read more
sourcefn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
Consume self to return Some equivalent value of Option<T>. Read more
sourceimpl<T> DecodeLimit for T where
T: Decode,
impl<T> DecodeLimit for T where
T: Decode,
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
pub fn as_any(&self) -> &(dyn Any + 'static)
pub fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
sourceimpl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
sourcefn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
Convert from a value of T into an equivalent instance of Self. Read more
sourcefn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of T. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
sourcepub fn unchecked_into(self) -> T
pub fn unchecked_into(self) -> T
The counterpart to unchecked_from.
sourceimpl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
sourcepub fn unique_saturated_into(self) -> T
pub fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of T.
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more