Struct luhn::Luhn
[−]
[src]
pub struct Luhn { /* fields omitted */ }
Luhn represents a thing that can generate or validate the Luhn character for a given input.
Methods
impl Luhn
[src]
fn new<S>(alphabet: S) -> Result<Luhn, LuhnError> where
S: AsRef<str>,
S: AsRef<str>,
Create a new Luhn instance from anything that can be coerced to a
&str
.
fn generate<S>(&self, s: S) -> Result<char, LuhnError> where
S: AsRef<str>,
S: AsRef<str>,
Given an input string, generate the Luhn character.
Returns an error if the input string is empty, or contains a character that is not in the input alphabet.
fn validate<S>(&self, s: S) -> Result<bool, LuhnError> where
S: AsRef<str>,
S: AsRef<str>,
Validates a Luhn check character. This assumes that the final character of the input string is the Luhn character, and it will validate that the remainder of the string is correct.
fn validate_with<S>(&self, s: S, check: char) -> Result<bool, LuhnError> where
S: AsRef<str>,
S: AsRef<str>,
Validates a Luhn check character. This is the same as the validate
method, but allows providing the Luhn check character out-of-band from
the input to validate.