#parser #random #validation #format #cnpj #cpf

no-std brids

Parse and generate random CPF and CNPJ, Brazil's ID numbers

8 releases (4 breaking)

0.5.1 Oct 2, 2024
0.5.0 Sep 30, 2024
0.4.0 Dec 21, 2018
0.3.1 Jun 19, 2018
0.1.0 Mar 28, 2018

#573 in Parser implementations

Download history 2/week @ 2024-07-01 5/week @ 2024-07-22 369/week @ 2024-09-30 20/week @ 2024-10-07 14/week @ 2024-10-14

403 downloads per month

MIT/Apache

34KB
645 lines

brids

Parse and generate random CPF and CNPJ, Brazil's ID numbers.

Usage

Add the following to your Cargo.toml:

[dependencies]
brids = "0.5"

Features

All dependencies are optional and disabled by default:

  • rand - enable to generate random numbers
  • serde - enable to (de)serialize numbers

no_std mode

To enable no_std mode, just disable the default features:

[dependencies]
brids = { version = "0.5", default-features = false }

Examples

Parse and format:

use brids::{Cnpj, Cpf};

let maybe_valid = "123.456.789-09".parse::<Cpf>();
assert!(maybe_valid.is_ok()); // Checks validity

let old_format = "123.456.789/09".parse::<Cpf>();
assert!(old_format.is_ok()); // Accepts the old format too

let unformatted = "12345678909".parse::<Cpf>().expect("Invalid CPF");
let formatted = unformatted.to_string(); // Formats
println!("CPF: {unformatted}"); // Formats too

// Generate random CNPJ and CPF numbers
println!("Random CNPJ number: {}", Cnpj::generate());
println!("Random CPF number: {}", Cpf::generate());

License

brids is licensed under either of the following, at your option:

Dependencies

~0–510KB