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"

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");

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> From<(&'a BaseCustom<char>, u64)> for Digits<'a>
[src]

Performs the conversion.

impl<'a, 'b> From<(&'a BaseCustom<char>, Digits<'b>)> for Digits<'a>
[src]

Performs the conversion.

impl<'a, 'b> From<(Digits<'a>, Digits<'b>)> for Digits<'a>
[src]

Performs the conversion.

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.

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

The resulting type after applying the + operator

The method for the + operator

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

The method for the += operator

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

The resulting type after applying the * operator

The method for the * operator

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

The method for the *= operator

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

The resulting type after applying the ^ operator

The method for the ^ operator

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

The method for the ^= operator

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

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more