#parser #format #validation #cpf #cnpj

brids

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

5 unstable releases

0.3.1 Jun 19, 2018
0.3.0 Apr 8, 2018
0.2.1 Mar 29, 2018
0.2.0 Mar 29, 2018
0.1.0 Mar 28, 2018

#71 in Parser implementations

Download history 35/week @ 2018-08-10 1/week @ 2018-08-17 8/week @ 2018-08-24 5/week @ 2018-09-07 2/week @ 2018-09-14 1/week @ 2018-09-21 12/week @ 2018-09-28 9/week @ 2018-10-05 36/week @ 2018-10-19 1/week @ 2018-10-26 20/week @ 2018-11-02

45 downloads per month

MIT/Apache

19KB
360 lines

brids

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

Usage

First, add the following to your Cargo.toml:

[dependencies]
brids = "0.3"

Next, add this to your crate root:

extern crate brids;

Examples

Parse and format:

extern crate brids;

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:

extern crate brids;

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

~676KB