Struct digits::Digits
[−]
[src]
pub struct Digits<'a> { /* fields omitted */ }
This struct acts similar to a full number with a custom numeric character base which is provided and mapped via a BaseCustom instance.
The underlying implementation for Digits 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
[src]
Add two Digits instances together.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let 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 base(&self) -> usize
[src]
Make numeric base size publicly available on Digits
fn gen<T>(&self, other: T) -> Self where
Self: From<(&'a BaseCustom<char>, T)>,
[src]
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_compat(&self, other: &Self) -> bool
[src]
Returns whether the two Digits instances have the same numeric base and character mapping.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let two = Digits::new(&base10, "2".to_string()); let three = Digits::new(&base10, "3".to_string()); assert!(two.is_compat(&three));
fn is_one(&self) -> bool
[src]
Returns bool value of if the number is one.
fn is_zero(&self) -> bool
[src]
Returns bool value of if the number is zero.
fn length(&self) -> usize
[src]
Returns a usize
of the total linked list length.
fn max_adjacent(&self) -> usize
[src]
Give the count for the maximum of the same adjacent characters for this digit.
Note that adjacent is a non-inclusive count. So for 7 numbers it's 1 adjacent to 6 which will return 6.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let num = Digits::new(&base10, "557771".to_string()); assert_eq!(num.max_adjacent(), 2);
The above example demonstrates that there are 2 adjacent 7s next to a 7 and that is the biggest adjacent set of numbers.
fn mul(&self, other: Self) -> Self
[src]
Multiply two Digits instances together.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let 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
[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.mut_add(two).to_s(), "13");
Output
"13"
fn mut_mul(&mut self, other: Self) -> Self
[src]
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.mut_mul(two).to_s(), "22");
Output
"22"
fn new<S>(mapping: &'a BaseCustom<char>, number: S) -> Digits<'a> where
S: Into<String>,
[src]
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.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let nine = Digits::new(&base10, "9".to_string()); assert_eq!(nine.to_s(), "9");
fn new_mapped(&self, places: Vec<usize>) -> Result<Self, &'static str>
[src]
Create a Digits from a Vector of from zero positional mappings for custom Digits numeric base.
Example
use digits::{BaseCustom,Digits}; let base16 = BaseCustom::<char>::new("0123456789abcdef".chars().collect()); let builder = Digits::new(&base16, "".to_string()); let num = builder.new_mapped(vec![1,0,2,1]).ok().unwrap(); assert_eq!(num.to_s(), "1021");
If zero had been Z in the example above the same vector vec![1,0,2,1]
would have
produced a Digits instance of a Hex value of "1Z21". The vector is the litteral positional
map of the character(s) via an index from zero regardless of numeric base.
If a number provided within the vector is higher than the numeric base size then the method
will return an Err(&'static str)
Result.
fn new_one(mapping: &'a BaseCustom<char>) -> Self
[src]
Creates a new Digits instance with value of one and the provided character mapping.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let one = Digits::new_one(&base10); assert_eq!(one.to_s(), "1");
fn new_zero(mapping: &'a BaseCustom<char>) -> Self
[src]
Creates a new Digits instance with value of zero and uses the provided character mapping.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let zero = Digits::new_zero(&base10); assert_eq!(zero.to_s(), "0");
fn next_non_adjacent(&mut self, adjacent: usize) -> Self
[src]
Returns the next Digits in incrementing that only allows the given number of adjacent number duplicates.
This will panic! if numeric base is less than 4.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let mut num = Digits::new(&base10, "98".to_string()); assert_eq!(num.next_non_adjacent(0).to_s(), "101");
fn one(&self) -> Self
[src]
Creates a new Digits instance with value of one and uses the current character mapping.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let nine = Digits::new(&base10, "9".to_string()); let one = nine.one(); assert_eq!(one.to_s(), "1");
fn pinky(&self) -> char
[src]
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
[src]
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
[src]
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>,
[src]
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.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let nine = Digits::new(&base10, "9".to_string()); let forty_two = nine.propagate("42".to_string()); assert_eq!(forty_two.to_s(), "42");
fn rcount(&self, character_index: u8) -> usize
[src]
Right count of digits character index.
Returns a usize
of how many Digits values from the right
match the BaseCustom index given for number.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("ABC3456789".chars().collect()); let num = Digits::new(&base10, "34BBB".to_string()); assert_eq!(num.rcount(1), 3);
Output
3
fn replicate(self) -> Self
[src]
An alias for clone
. Useful for unboxing.
fn succ(&mut self) -> Self
[src]
Plus one.
fn to_s(&self) -> String
[src]
Gives the full value of all digits within the linked list as a String.
fn to_string(&self) -> String
[src]
Gives the full value of all digits within the linked list as a String.
fn zero(&self) -> Self
[src]
Creates a new Digits instance with value of zero and the current character mapping.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let nine = Digits::new(&base10, "9".to_string()); let zero = nine.zero(); assert_eq!(zero.to_s(), "0");
fn zero_fill(&mut self, length: usize)
[src]
Zero fills the left of the current number up to a total character length.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let mut nine = Digits::new(&base10, "9".to_string()); nine.zero_fill(4); assert_eq!(nine.to_s(), "0009");
fn zero_trim(&mut self)
[src]
Zero trims the left of the current number.
Example
use digits::{BaseCustom,Digits}; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); let mut nine = Digits::new(&base10, "0009".to_string()); nine.zero_trim(); assert_eq!(nine.to_s(), "9");
Trait Implementations
impl<'a> Clone for Digits<'a>
[src]
fn clone(&self) -> Digits<'a>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a> From<(&'a BaseCustom<char>, u64)> for Digits<'a>
[src]
impl<'a, 'b> From<(&'a BaseCustom<char>, Digits<'b>)> for Digits<'a>
[src]
impl<'a, 'b> From<(Digits<'a>, Digits<'b>)> for Digits<'a>
[src]
impl<'a> Into<String> for Digits<'a>
[src]
impl<'a> Display for Digits<'a>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<'a> Debug for Digits<'a>
[src]
impl<'a> PartialEq for Digits<'a>
[src]
fn eq(&self, other: &Digits<'a>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> Add for Digits<'a>
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self
[src]
Performs the +
operation.
impl<'a> AddAssign for Digits<'a>
[src]
fn add_assign(&mut self, other: Self)
[src]
Performs the +=
operation.
impl<'a> Mul for Digits<'a>
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self
[src]
Performs the *
operation.
impl<'a> MulAssign for Digits<'a>
[src]
fn mul_assign(&mut self, other: Self)
[src]
Performs the *=
operation.
impl<'a> BitXor for Digits<'a>
[src]
type Output = Self
The resulting type after applying the ^
operator.
fn bitxor(self, other: Self) -> Self
[src]
Performs the ^
operation.
impl<'a> BitXorAssign for Digits<'a>
[src]
fn bitxor_assign(&mut self, other: Self)
[src]
Performs the ^=
operation.
impl<'a> PartialOrd for Digits<'a>
[src]
fn partial_cmp(&self, other: &Digits<'a>) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more