Struct digits::Digits
[−]
[src]
pub struct Digits<'a> { /* fields omitted */ }
This struct acts similar to a full number with a custom numeric character base. But the underlying implementation is a linked list where all the methods recurse as far as need to to implement the operations.
Methods
impl<'a> Digits<'a>
[src]
fn add(&self, other: Self) -> Self
Add two Digits instances together.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let mut eleven = Digits::new(&base10, "11".to_string()); let two = Digits::new(&base10, "2".to_string()); assert_eq!(eleven.add(two).to_s(), "13");
Output
"13"
fn gen<T>(&self, other: T) -> Self where
Self: From<(&'a BaseCustom<char>, T)>,
Self: From<(&'a BaseCustom<char>, T)>,
Allows you to generate/encode a Digits from a u64
or other Digits
even if they are of a
different numeric base.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let two = Digits::new(&base10, "2".to_string()); let three = two.gen(3_u64); assert_eq!(three.to_s(), "3");
fn is_one(&self) -> bool
Returns bool value of if the number is one.
fn is_zero(&self) -> bool
Returns bool value of if the number is zero.
fn length(&self) -> usize
Returns a usize
of the total linked list length.
fn mul(&self, other: Self) -> Self
Multiply two Digits instances together.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let mut eleven = Digits::new(&base10, "11".to_string()); let two = Digits::new(&base10, "2".to_string()); assert_eq!(eleven.mul(two).to_s(), "22");
Output
"22"
fn mut_add(&mut self, other: Self) -> Self
Add two Digits instances together. The one the mut_add
method is called on
must be mutable and modifies itself. The other is consumed.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let mut eleven = Digits::new(&base10, "11".to_string()); let two = Digits::new(&base10, "2".to_string()); assert_eq!(eleven.mut_add(two).to_s(), "13");
Output
"13"
fn mut_mul(&mut self, other: Self) -> Self
Multiply two Digits instances together. The one the mut_mul
method is called on
must be mutable and modifies itself. The other is consumed.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let mut eleven = Digits::new(&base10, "11".to_string()); let two = Digits::new(&base10, "2".to_string()); assert_eq!(eleven.mut_mul(two).to_s(), "22");
Output
"22"
fn new<S>(mapping: &'a BaseCustom<char>, number: S) -> Digits<'a> where
S: Into<String>,
S: Into<String>,
Creates a new Digits instance with the provided character set and value.
The first parameter must be a BaseCustom object which defines and maps all values. The second parameter is a string value with all valid characters from the BaseCustom set.
fn new_one(mapping: &'a BaseCustom<char>) -> Self
Creates a new Digits instance with value of one and the provided character mapping.
fn new_zero(mapping: &'a BaseCustom<char>) -> Self
Creates a new Digits instance with value of zero and uses the provided character mapping.
fn one(&self) -> Self
Creates a new Digits instance with value of one and uses the current character mapping.
fn pinky(&self) -> char
The “pinky” is the smallest digit
a.k.a. current digit in the linked list
a.k.a. the right most digit.
This will be a char
value for that digit.
fn pow(&mut self, pwr: Self) -> Self
Multiplies self times the power-of given Digits parameter.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let mut eleven = Digits::new(&base10, "11".to_string()); let two = Digits::new(&base10, "2".to_string()); assert_eq!(eleven.pow(two).to_s(), "121");
Output
"121"
fn pred_till_zero(&mut self) -> Self
Minuses one unless it's zero, then it just returns a Digits instance of zero.
fn propagate<S>(&self, number: S) -> Self where
S: Into<String>,
S: Into<String>,
Creates a new Digits instance with the internal character set and given value.
The parameter is a string value with all valid characters from the BaseCustom set.
fn replicate(self) -> Self
An alias for clone
. Useful for unboxing.
fn succ(&mut self) -> Self
Plus one.
fn to_s(&self) -> String
Gives the full value of all digits within the linked list as a String.
fn to_string(&self) -> String
Gives the full value of all digits within the linked list as a String.
fn zero(&self) -> Self
Creates a new Digits instance with value of zero and the current character mapping.
Trait Implementations
impl<'a> Clone for Digits<'a>
[src]
fn clone(&self) -> Digits<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more