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]

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"

Returns bool value of if the number is one.

Returns bool value of if the number is zero.

Returns a usize of the total linked list length.

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"

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"

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"

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.

Creates a new Digits instance with value of one and the provided character mapping.

Creates a new Digits instance with value of zero and uses the provided character mapping.

Creates a new Digits instance with value of one and uses the current character mapping.

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.

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"

Minuses one unless it's zero, then it just returns a Digits instance of zero.

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.

An alias for clone. Useful for unboxing.

Plus one.

Gives the full value of all digits within the linked list as a String.

Gives the full value of all digits within the linked list as a String.

Creates a new Digits instance with value of zero and the current character mapping.

Trait Implementations

impl<'a> Clone for Digits<'a>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> Into<String> for Digits<'a>
[src]

impl<'a> Display for Digits<'a>
[src]

Formats the value using the given formatter. Read more

impl<'a> Debug for Digits<'a>
[src]

Formats the value using the given formatter.