3 releases (stable)

1.0.1 Aug 28, 2020
1.0.0 Sep 24, 2019
0.1.0 Aug 20, 2015

#99 in Finance

Download history 598/week @ 2024-12-25 3678/week @ 2025-01-01 5617/week @ 2025-01-08 5676/week @ 2025-01-15 6163/week @ 2025-01-22 6162/week @ 2025-01-29 6058/week @ 2025-02-05 4653/week @ 2025-02-12 6232/week @ 2025-02-19 6903/week @ 2025-02-26 8037/week @ 2025-03-05 7446/week @ 2025-03-12 6178/week @ 2025-03-19 2642/week @ 2025-03-26 2161/week @ 2025-04-02 2945/week @ 2025-04-09

15,443 downloads per month
Used in 4 crates

MIT license

9KB
131 lines

Validates strings and computes check digits using the Luhn algorithm.

It's not a great checksum, but it's used in a bunch of places (credit card numbers, ISIN codes, etc.). More information is available on wikipedia.


luhn-rs

Validates strings and computes check digits using the Luhn algorithm.

Usage

Add luhn under [dependencies] in your Cargo.toml:

[dependencies]
luhn = "1.0.1"

Use the validator!

luhn::valid("4111111111111111"); // true

Append check digits to your strings and make them Luhn-valid!

// A string which doesn't validate
let mut s = "11111111".to_string();
assert!(!valid(&s));

// Let's fix that
s.push(luhn::checksum(s.as_bytes()) as char);
assert_eq!(s, "111111118");
assert!(valid(&s));

Dependencies

~11KB