Crates.io | brids |
lib.rs | brids |
version | 0.5.1 |
source | src |
created_at | 2018-03-28 03:20:26.441852 |
updated_at | 2024-10-02 07:52:57.347063 |
description | Parse and generate random CPF and CNPJ, Brazil's ID numbers. |
homepage | |
repository | https://gitlab.com/ricvelozo/brids-rs |
max_upload_size | |
id | 57846 |
size | 55,985 |
Parse and generate random CPF and CNPJ, Brazil's ID numbers.
Add the following to your Cargo.toml
:
[dependencies]
brids = "0.5"
All dependencies are optional and disabled by default:
no_std
modeTo enable no_std
mode, just disable the default features:
[dependencies]
brids = { version = "0.5", default-features = false }
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());
brids
is licensed under either of the following, at your option: