pub trait NumeralSystem<T> {
// Required methods
fn decode(&self, rep: &str) -> Result<T, StrError>;
fn encode(&self, val: T) -> Result<String, TryFromIntError>;
}
Expand description
NumeralSystem
provides conversions to and from representations in the given system.
Required Methods§
Sourcefn decode(&self, rep: &str) -> Result<T, StrError>
fn decode(&self, rep: &str) -> Result<T, StrError>
Given a NumeralSystem
and a number’s representation
in that system, return the number.
Returns Err
if this function encounters a character not in the system,
or if an int to int conversion fails.
Sourcefn encode(&self, val: T) -> Result<String, TryFromIntError>
fn encode(&self, val: T) -> Result<String, TryFromIntError>
Given a NumeralSystem
and a number, return the
representation of that number in the system.
Returns Err
if an int to int conversion fails.
This will interpret signed integers as if their bits represented their unsigned counterparts.