Expand description
Reusable helpers for validating digit sequences with the Luhn algorithm.
§Examples
use luhncalc::{analyze, calculate_check_digit, validate};
assert!(!validate("1234567890")?);
assert_eq!(calculate_check_digit("1234567890")?, '3');
let analysis = analyze("12345678903")?;
assert!(analysis.valid);
assert_eq!(analysis.next_check_digit, '1');Structs§
- Analysis
- The combined result of validating a digit sequence and computing the next check digit for that sequence.
Enums§
- Digit
Sequence Error - Error returned when the provided digit sequence cannot be processed.
Functions§
- analyze
- Validate a sequence and calculate its next check digit in one call.
- calculate_
check_ digit - Calculate the check digit that should be appended to a sequence.
- validate
- Validate whether a digit sequence passes the Luhn algorithm.