Struct Luhn

Source
pub struct Luhn { /* private fields */ }
Expand description

Luhn represents a thing that can generate or validate the Luhn character for a given input.

Implementations§

Source§

impl Luhn

Source

pub fn new<S>(alphabet: S) -> Result<Luhn, LuhnError>
where S: AsRef<str>,

Create a new Luhn instance from anything that can be coerced to a &str.

Source

pub fn generate<S>(&self, s: S) -> Result<char, LuhnError>
where 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.

Source

pub fn validate<S>(&self, s: S) -> Result<bool, LuhnError>
where 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.

Source

pub fn validate_with<S>(&self, s: S, check: char) -> Result<bool, LuhnError>
where 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.

Trait Implementations§

Source§

impl Debug for Luhn

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Luhn

§

impl RefUnwindSafe for Luhn

§

impl Send for Luhn

§

impl Sync for Luhn

§

impl Unpin for Luhn

§

impl UnwindSafe for Luhn

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.