Skip to main content

Nat

Struct Nat 

Source
pub struct Nat(/* private fields */);
Expand description

A natural number of any size: Lean’s Nat.

Converts from every unsigned integer type, and back with TryFrom when the value fits. It prints and parses as decimal digits.

use inlean_runtime::Nat;
let n: Nat = "340282366920938463463374607431768211456".parse().unwrap(); // 2^128
assert!(u128::try_from(&n).is_err());
assert_eq!(Nat::from(7u8).to_string(), "7");

A Nat is Send and Sync, like an integer: it holds a number of its own. A clone of a number too large for a machine word copies its digits.

Implementations§

Source§

impl Nat

Source

pub fn from_limbs(limbs: &[u64]) -> Nat

The number with these 64-bit limbs, least significant first: the form in which fixed-width integer libraries hold their words.

use inlean_runtime::Nat;
assert_eq!(Nat::from_limbs(&[0, 1]), Nat::from(1u128 << 64));
Source

pub fn to_limbs(&self) -> Vec<u64>

The 64-bit limbs of the number, least significant first, without leading zeros.

Trait Implementations§

Source§

impl Clone for Nat

Source§

fn clone(&self) -> Nat

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Nat

Source§

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

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

impl Default for Nat

Source§

fn default() -> Nat

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

impl Display for Nat

Source§

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

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

impl Drop for Nat

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Eq for Nat

Source§

impl From<&Nat> for Nat

Source§

fn from(value: &Nat) -> Nat

Converts to this type from the input type.
Source§

impl From<Nat> for Int

Source§

fn from(value: Nat) -> Int

Converts to this type from the input type.
Source§

impl<const N: usize> From<[u64; N]> for Nat

Source§

fn from(limbs: [u64; N]) -> Nat

The number with these limbs, least significant first.

Source§

impl From<u8> for Nat

Source§

fn from(value: u8) -> Nat

Converts to this type from the input type.
Source§

impl From<u16> for Nat

Source§

fn from(value: u16) -> Nat

Converts to this type from the input type.
Source§

impl From<u32> for Nat

Source§

fn from(value: u32) -> Nat

Converts to this type from the input type.
Source§

impl From<u64> for Nat

Source§

fn from(value: u64) -> Nat

Converts to this type from the input type.
Source§

impl From<u128> for Nat

Source§

fn from(value: u128) -> Nat

Converts to this type from the input type.
Source§

impl From<usize> for Nat

Source§

fn from(value: usize) -> Nat

Converts to this type from the input type.
Source§

impl FromStr for Nat

Source§

type Err = ParseNatError

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Nat, ParseNatError>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Nat

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Nat

Source§

fn cmp(&self, other: &Nat) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Nat

Source§

fn eq(&self, other: &Nat) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Nat

Source§

fn partial_cmp(&self, other: &Nat) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Send for Nat

Source§

impl Sync for Nat

Source§

impl TryFrom<&Nat> for u8

Source§

type Error = TooLarge

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

fn try_from(value: &Nat) -> Result<u8, TooLarge>

Performs the conversion.
Source§

impl TryFrom<&Nat> for u16

Source§

type Error = TooLarge

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

fn try_from(value: &Nat) -> Result<u16, TooLarge>

Performs the conversion.
Source§

impl TryFrom<&Nat> for u32

Source§

type Error = TooLarge

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

fn try_from(value: &Nat) -> Result<u32, TooLarge>

Performs the conversion.
Source§

impl TryFrom<&Nat> for u64

Source§

type Error = TooLarge

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

fn try_from(value: &Nat) -> Result<u64, TooLarge>

Performs the conversion.
Source§

impl TryFrom<&Nat> for usize

Source§

type Error = TooLarge

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

fn try_from(value: &Nat) -> Result<usize, TooLarge>

Performs the conversion.
Source§

impl TryFrom<&Nat> for u128

Source§

type Error = TooLarge

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

fn try_from(value: &Nat) -> Result<u128, TooLarge>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<&Nat> for [u64; N]

Source§

fn try_from(value: &Nat) -> Result<[u64; N], TooLarge>

The limbs of the number, least significant first, when it is below 2^(64·N).

Source§

type Error = TooLarge

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

impl TryFrom<Nat> for u8

Source§

type Error = TooLarge

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

fn try_from(value: Nat) -> Result<u8, TooLarge>

Performs the conversion.
Source§

impl TryFrom<Nat> for u16

Source§

type Error = TooLarge

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

fn try_from(value: Nat) -> Result<u16, TooLarge>

Performs the conversion.
Source§

impl TryFrom<Nat> for u32

Source§

type Error = TooLarge

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

fn try_from(value: Nat) -> Result<u32, TooLarge>

Performs the conversion.
Source§

impl TryFrom<Nat> for u64

Source§

type Error = TooLarge

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

fn try_from(value: Nat) -> Result<u64, TooLarge>

Performs the conversion.
Source§

impl TryFrom<Nat> for usize

Source§

type Error = TooLarge

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

fn try_from(value: Nat) -> Result<usize, TooLarge>

Performs the conversion.
Source§

impl TryFrom<Nat> for u128

Source§

type Error = TooLarge

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

fn try_from(value: Nat) -> Result<u128, TooLarge>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Nat> for [u64; N]

Source§

type Error = TooLarge

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

fn try_from(value: Nat) -> Result<[u64; N], TooLarge>

Performs the conversion.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Nat

§

impl !UnwindSafe for Nat

§

impl Forget for Nat

§

impl Freeze for Nat

§

impl Move for Nat

§

impl Unpin for Nat

§

impl UnsafeUnpin for Nat

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> KeptByLeanForAllThreads for T
where T: Sync,

Source§

impl<T> Pass<T> for T

Source§

fn pass<C>(self) -> Value<C>
where C: Codec<Rust = T>,

Source§

impl<T> Slot<T> for T

Source§

fn of(collection: T) -> T

Source§

fn inner(&self) -> &T

Source§

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

The collection for changing, which is this holder’s alone afterwards.
Source§

fn into_inner(self) -> T

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.