| Crates.io | luhn |
| lib.rs | luhn |
| version | 1.0.1 |
| created_at | 2015-08-20 23:50:21.923956+00 |
| updated_at | 2020-08-28 03:59:58.700683+00 |
| description | A Luhn validation library |
| homepage | |
| repository | https://github.com/jeffcarp/luhn-rs |
| max_upload_size | |
| id | 2887 |
| size | 9,812 |
Validates strings and computes check digits using the Luhn algorithm.
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));