[−][src]Trait natural_numbers::Nat
Trait for types implementing natural numbers.
Required methods
fn value(&self) -> u32
Converts a value of type Nat into the corresponding value of type u32.
Examples
use natural_numbers::{Nat,U32Nat}; let zero = U32Nat::zero(); assert_eq!(zero.value(), 0);
fn wrap(n: u32) -> Self
Converts a value of type u32 into the corresponding value of type Nat.
Examples
use natural_numbers::{Nat,U32Nat}; assert_eq!(U32Nat::wrap(0), U32Nat::zero());
fn zero() -> Self
fn is_zero(&self) -> bool
fn succ(&self) -> Self
The successor of a value.
Examples
use natural_numbers::{Nat,U32Nat}; assert_eq!(U32Nat::wrap(1), U32Nat::zero().succ());
Provided methods
fn pred(&self) -> Option<Self>
The value of which this is a successor, or None if the value is zero.
Examples
use natural_numbers::{Nat,U32Nat}; let one = U32Nat::zero().succ(); assert_eq!(one.pred().unwrap(), U32Nat::zero());
fn add(&self, n: &Self) -> Self
The sum of two values.
Examples
use natural_numbers::{Nat,U32Nat}; let two = U32Nat::wrap(2); let three = U32Nat::wrap(3); let five = U32Nat::wrap(5); assert_eq!(two.add(&three), five);