[−][src]Struct based::Base
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]
&self,
rep: &str
) -> Result<T, UnknownChar>
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
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,