use std::num::TryFromIntError;
mod single_base;
pub use single_base::*;
#[derive(Debug)]
pub enum StrError {
UnknownChar(char),
Try(TryFromIntError)
}
impl std::fmt::Display for StrError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
StrError::UnknownChar(c) => write!(f, "Encountered char {} not in base", c),
StrError::Try(t) => t.fmt(f)
}
}
}
impl std::error::Error for StrError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
StrError::UnknownChar(_) => None,
StrError::Try(t) => Some(t)
}
}
}
impl From<TryFromIntError> for StrError {
fn from(err: TryFromIntError) -> StrError {
StrError::Try(err)
}
}
pub trait NumeralSystem<T> {
fn decode(&self, rep: &str) -> Result<T, StrError>;
fn encode(&self, val: T) -> Result<String, TryFromIntError>;
}