#parser #format #validation #cpf #cnpj

brids

Parse and generate random CPF/ICN and CNPJ, Brazil’s ID numbers

6 releases (3 breaking)

✓ Uses Rust 2018 edition

0.4.0 Dec 21, 2018
0.3.1 Jun 19, 2018
0.3.0 Apr 8, 2018
0.2.1 Mar 29, 2018
0.1.0 Mar 28, 2018

#73 in Parser implementations

Download history 6/week @ 2018-12-14 68/week @ 2018-12-21 1/week @ 2018-12-28 10/week @ 2019-01-04 6/week @ 2019-01-11 2/week @ 2019-01-18 4/week @ 2019-01-25 1/week @ 2019-02-01 2/week @ 2019-02-08 2/week @ 2019-02-22 13/week @ 2019-03-01 2/week @ 2019-03-08 7/week @ 2019-03-15 35/week @ 2019-03-22

69 downloads per month

MIT/Apache

33KB
628 lines

brids

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

Usage

Add the following to your Cargo.toml:

[dependencies]
brids = "0.4"

Examples

Parse and format:

use brids::Cpf;
use std::io::{stdin, stdout, Write};

fn main() {
    print!("Input a CPF/ICN number: ");
    stdout().flush().ok();

    let mut input = String::with_capacity(14);
    stdin().read_line(&mut input).ok();

    match input.trim().parse::<Cpf>() {
        Ok(cpf) => println!("{} is a valid number.", cpf),
        Err(err) => println!("Error: {}", err),
    }
}

Generate random CNPJ and CPF/ICN numbers:

use brids::{Cnpj, Cpf};

fn main() {
    println!("Random CNPJ number: {}", Cnpj::generate());
    println!("Random CPF/ICN number: {}", Cpf::generate());
}

License

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

Dependencies

~1MB
~10K SLoC