#validation #no-alloc #validate

no-std creditcard

Zero-dependency credit card parser and validator

1 unstable release

Uses new Rust 2024

0.1.0 Jan 7, 2025

#303 in No standard library

Download history 84/week @ 2025-01-01 46/week @ 2025-01-08 4/week @ 2025-02-05 1/week @ 2025-02-12 5/week @ 2025-02-19 117/week @ 2025-02-26 18/week @ 2025-03-05

141 downloads per month
Used in wary

MIT/Apache

16KB
329 lines

Credit Card

Zero-dependency credit card number validation and parsing for Rust.

Basic example

use creditcard::{CreditCard, CreditCardKind};

let card = "4111111111111111".parse::<CreditCard>().unwrap();

assert_eq!(card.kind(), CreditCardKind::Visa);
assert_eq!(card.pan(), 4111111111111111);

Benchmarks

See the benches directory for basic micro-benchmarks.

benchmark creditcard card-validate
too short 27.740ns 280.77ns
too long 23.787ns 280.06ns
invalid 18.113ns 279.38ns
valid 28.651ns 139.38ns

lib.rs:

Ported from https://github.com/valeriansaliou/rs-card-validate/blob/master/src/lib.rs

No runtime deps