Struct Base

Source
pub struct Base { /* private fields */ }
Expand description

Base represents a numeral system with single-character digits.

When creating a new numeral system from a given string slice, the value of each character is its index in the slice, e.g. the first character has value 0, the second has value 1, etc.

If the given slice has at least one duplicate character, parsing will produce an Err.

§Examples

use based::*;
 
let base16: based::Base = "0123456789abcdef".parse().unwrap();
assert_eq!("a", base16.encode(10).unwrap());

Trait Implementations§

Source§

impl Display for Base

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Base

Source§

type Err = DuplicateCharacterError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl NumeralSystem<i128> for Base

Source§

fn decode(&self, rep: &str) -> Result<i128, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: i128) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<i16> for Base

Source§

fn decode(&self, rep: &str) -> Result<i16, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: i16) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<i32> for Base

Source§

fn decode(&self, rep: &str) -> Result<i32, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: i32) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<i64> for Base

Source§

fn decode(&self, rep: &str) -> Result<i64, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: i64) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<i8> for Base

Source§

fn decode(&self, rep: &str) -> Result<i8, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: i8) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<isize> for Base

Source§

fn decode(&self, rep: &str) -> Result<isize, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: isize) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<u128> for Base

Source§

fn decode(&self, rep: &str) -> Result<u128, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: u128) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<u16> for Base

Source§

fn encode(&self, val: u16) -> Result<String, TryFromIntError>

Never produces Err.

Source§

fn decode(&self, rep: &str) -> Result<u16, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

impl NumeralSystem<u32> for Base

Source§

fn decode(&self, rep: &str) -> Result<u32, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: u32) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<u64> for Base

Source§

fn decode(&self, rep: &str) -> Result<u64, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

fn encode(&self, val: u64) -> Result<String, TryFromIntError>

Given a NumeralSystem and a number, return the representation of that number in the system. Read more
Source§

impl NumeralSystem<u8> for Base

Source§

fn encode(&self, val: u8) -> Result<String, TryFromIntError>

Never produces Err.

Source§

fn decode(&self, rep: &str) -> Result<u8, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more
Source§

impl NumeralSystem<usize> for Base

Source§

fn encode(&self, val: usize) -> Result<String, TryFromIntError>

Never produces Err.

Source§

fn decode(&self, rep: &str) -> Result<usize, StrError>

Given a NumeralSystem and a number’s representation in that system, return the number. Read more

Auto Trait Implementations§

§

impl Freeze for Base

§

impl RefUnwindSafe for Base

§

impl Send for Base

§

impl Sync for Base

§

impl Unpin for Base

§

impl UnwindSafe for Base

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.