Struct digits::prelude::BaseCustom
[−]
[src]
pub struct BaseCustom<T> { pub base: u64, // some fields omitted }
The BaseCustom struct holds the information to perform number conversions
via the gen
and decimal
methods.
A new instance of BaseCustom can be created with either
BaseCustom::<char>::new(Vec<char>)
BaseCustom::<char>::from_ordinal_range(Range)
BaseCustom::<String>::new(String, Option<char>)
If you are going to provide a delimiter you need to use the <String>
implementation.
A delimiter is optional.
The primitives for BaseCustom get built from the provides characters or string groups and conversion methods are available to use then. String groupings will be single character strings if no delimiter is given, otherwise they may be strings of any length split only by the delimiter provided.
Fields
base: u64
The size of the base
Methods
impl BaseCustom<char>
[src]
fn new(chars: Vec<char>) -> BaseCustom<char>
[src]
'new' creates a new BaseCustom instance and propogates the values for converting numeric bases.
new
for BaseCustom<char>
requires a Vec<char>
as its parameters and units
for measuring the custom numeric base will only be one character long each.
fn gen(&self, input_val: u64) -> String
[src]
gen
returns a String computed from the character mapping and
positional values the given u64 parameter evalutes to for your
custom base
Example
use base_custom::BaseCustom; let base2 = BaseCustom::<char>::new(vec!['0','1']); assert_eq!(base2.gen(3), "11");
Output
"11"
fn char(&self, input_val: usize) -> Option<char>
[src]
char
returns a char straight from the character mapping.
decimal value must be within character range for a Some result.
Example
use base_custom::BaseCustom; let base10 = BaseCustom::<char>::new("0123456789".chars().collect()); assert_eq!(base10.char(9), Some('9'));
Output
'9'
fn decimal<S>(&self, input_val: S) -> u64 where
S: Into<String>,
[src]
S: Into<String>,
decimal
returns a u64 value on computed from the units that form
the custom base.
Example
use base_custom::BaseCustom; let base2 = BaseCustom::<char>::new(vec!['0','1']); assert_eq!(base2.decimal("00011"), 3);
Output
3
fn zero(&self) -> &char
[src]
Returns the zero value of your custom base
fn one(&self) -> &char
[src]
Returns the one value of your custom base
fn nth(&self, pos: usize) -> Option<&char>
[src]
Returns the nth value of your custom base
Like most indexing operations, the count starts from zero, so nth(0) returns the first value, nth(1) the second, and so on.
fn from_ordinal_range(range: Range<u32>) -> BaseCustom<char>
[src]
Create a custom numeric base from an ascii range of ordinal values
This method currently restricts the ascii character range of the
95 typical characters starting from 32 and ending with 127. If you'd
like to use characters outside of this range please use the new
method.
impl BaseCustom<String>
[src]
fn new<S>(chars: S, delim: Option<char>) -> BaseCustom<String> where
S: Into<String>,
[src]
S: Into<String>,
'new' creates a new BaseCustom instance and propogates the values for converting numeric bases.
new
for BaseCustom<String>
requires a String
as its first parameter and units
for measuring the custom numeric base can be one character long, or many in length.
The second parameter is of Option<char>
is a delimiter option for determining whether
to split the string into single character length strings or possibly multiple length
if the delimiter is partitioning the string in such a way.
fn gen(&self, input_val: u64) -> String
[src]
gen
returns a String computed from the character mapping and
positional values the given u64 parameter evalutes to for your
custom base
Example
use base_custom::BaseCustom; let base2 = BaseCustom::<String>::new("01", None); assert_eq!(base2.gen(3), "11");
Output
"11"
fn decimal<S>(&self, input_val: S) -> u64 where
S: Into<String>,
[src]
S: Into<String>,
decimal
returns a u64 value on computed from the units that form
the custom base.
Example
use base_custom::BaseCustom; let base2 = BaseCustom::<String>::new("01", None); assert_eq!(base2.decimal("00011"), 3);
Output
3
fn zero(&self) -> &str
[src]
Returns the zero value of your custom base
fn one(&self) -> &str
[src]
Returns the one value of your custom base
fn nth(&self, pos: usize) -> Option<&str>
[src]
Returns the nth value of your custom base
Like most indexing operations, the count starts from zero, so nth(0) returns the first value, nth(1) the second, and so on.
Trait Implementations
impl PartialEq<BaseCustom<String>> for BaseCustom<String>
[src]
fn eq(&self, other: &BaseCustom<String>) -> 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 PartialEq<BaseCustom<char>> for BaseCustom<char>
[src]
fn eq(&self, other: &BaseCustom<char>) -> 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 Debug for BaseCustom<char>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl Debug for BaseCustom<String>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl<T> Clone for BaseCustom<T> where
T: Clone,
[src]
T: Clone,
fn clone(&self) -> BaseCustom<T>
[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