[][src]Struct based::Base

pub struct Base { /* fields omitted */ }

The Base of a numeral system.

Methods

impl Base[src]

pub fn new(base: &str) -> Base[src]

Creates a new base from the given string slice.

The value of each character is its index in the slice, e.g. the first character has value 1, the second value 2, etc.

The behavior of the function is undefined when a character is present more than once in the given string slice.

Examples

use based::Base;

let base16 = based::Base::new("0123456789abcdef");

pub fn from_str<T: AddAssign + Default + MulAssign + From<usize>>(
    &self,
    rep: &str
) -> Result<T, UnknownChar>
[src]

Given a base and a number's representation in that base, return the number.

Returns Err if it encounters a character not in the Base.

Examples

use based::Base;

let base16 = Base::new("0123456789abcdef");
let sixteen = base16.from_str::<usize>("10");
assert_eq!(sixteen.unwrap(), 16);

pub fn rep<T: Into<usize>>(&self, val: T) -> String[src]

Given a base and a number, return the representation of the number in the base.

Examples

use based::Base;

let base16 = Base::new("0123456789abcdef");
let sixteen = base16.rep::<usize>(16);
assert_eq!(sixteen, "10");

Trait Implementations

impl Display for Base[src]

Auto Trait Implementations

impl RefUnwindSafe for Base

impl Send for Base

impl Sync for Base

impl Unpin for Base

impl UnwindSafe for Base

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.