pub trait Calculator<T>{
// Required methods
fn name(&self) -> &'static str;
fn calculate(&self, s: &str) -> Result<T, CheckDigitError>;
// Provided methods
fn number_of_check_digit_chars(&self) -> usize { ... }
fn create(&self, s: &str) -> Result<String, CheckDigitError> { ... }
fn validate<S>(&self, s: S) -> Result<(), CheckDigitError>
where Self: Sized,
S: AsRef<str> { ... }
fn is_valid<S>(&self, s: S) -> bool
where Self: Sized,
S: AsRef<str> { ... }
}Expand description
Trait for types that implement check digit algorithms.
Required Methods§
Sourcefn calculate(&self, s: &str) -> Result<T, CheckDigitError>
fn calculate(&self, s: &str) -> Result<T, CheckDigitError>
Calculate a check digit for the provided string.
Provided Methods§
Sourcefn number_of_check_digit_chars(&self) -> usize
fn number_of_check_digit_chars(&self) -> usize
Return the number of characters used as the check digit. Currently it is assumed that these are the n right-most characters in the input string.
Sourcefn create(&self, s: &str) -> Result<String, CheckDigitError>
fn create(&self, s: &str) -> Result<String, CheckDigitError>
Create a new string with the original data plus check digit.
Sourcefn validate<S>(&self, s: S) -> Result<(), CheckDigitError>
fn validate<S>(&self, s: S) -> Result<(), CheckDigitError>
Validate that the string is valid and that it contains a valid check digit.