3 releases (stable)

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

#863 in Algorithms

Download history 2898/week @ 2023-11-20 3499/week @ 2023-11-27 2875/week @ 2023-12-04 2687/week @ 2023-12-11 1915/week @ 2023-12-18 872/week @ 2023-12-25 1602/week @ 2024-01-01 2536/week @ 2024-01-08 1710/week @ 2024-01-15 1687/week @ 2024-01-22 2408/week @ 2024-01-29 2093/week @ 2024-02-05 1964/week @ 2024-02-12 2305/week @ 2024-02-19 2867/week @ 2024-02-26 3576/week @ 2024-03-04

10,753 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