3 releases (stable)

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

#1351 in Algorithms

Download history 1562/week @ 2024-07-23 1936/week @ 2024-07-30 2667/week @ 2024-08-06 2748/week @ 2024-08-13 2809/week @ 2024-08-20 2924/week @ 2024-08-27 3817/week @ 2024-09-03 2856/week @ 2024-09-10 1915/week @ 2024-09-17 2652/week @ 2024-09-24 3071/week @ 2024-10-01 3624/week @ 2024-10-08 2924/week @ 2024-10-15 3764/week @ 2024-10-22 6014/week @ 2024-10-29 7326/week @ 2024-11-05

20,545 downloads per month
Used in 4 crates

MIT license

9KB
131 lines

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));

lib.rs:

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.

Dependencies

~11KB