1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
// lib.rs
//
// Copyright 2018 Ricardo Silva Veloso <ricvelozo@gmail.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT License
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: (MIT OR Apache-2.0)
//! Parse and generate random CPF/ICN and CNPJ, Brazil's ID numbers.
//!
//! # Usage
//!
//! Add the following to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! brids = "0.4"
//! ```
//!
//! # Dependencies
//!
//! The [`rand`] crate is an optional dependency enabled by default. To disable, use:
//!
//! [`rand`]: https://crates.io/crates/rand
//!
//! ```toml
//! [dependencies]
//! brids = { version = "0.4", default-features = false }
//! ```
//!
//! The [`serde`] crate is an optional dependency **disabled by default**. To enable, use:
//!
//! [`serde`]: https://crates.io/crates/serde
//!
//! ```toml
//! [dependencies]
//! brids = { version = "0.4", features = ["serde"] }
//! ```
//!
//! # Examples
//!
//! Parse and format:
//!
//! ```rust
//! 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:
//!
//! ```rust
//! use brids::{Cnpj, Cpf};
//!
//! fn main() {
//! println!("Random CNPJ number: {}", Cnpj::generate());
//! println!("Random CPF/ICN number: {}", Cpf::generate());
//! }
//! ```
//!
//! Using a different generator:
//!
//! ```rust
//! use brids::{Cnpj, Cpf};
//! use rand::prelude::*;
//!
//! fn main() {
//! let mut rng = SmallRng::seed_from_u64(123);
//! println!("Random CNPJ number: {}", rng.gen::<Cnpj>());
//! println!("Random CPF/ICN number: {}", rng.gen::<Cpf>());
//! }
//! ```
//!
//! Serialize and deserialize (you must enable the [`serde` feature](#dependencies)):
//!
//! ```rust, ignore
//! use brids::Cnpj;
//! use serde_derive::{Deserialize, Serialize};
//! use serde_json;
//!
//! #[derive(Debug, PartialEq, Serialize, Deserialize)]
//! struct Company<'a> {
//! name: &'a str,
//! cnpj: Cnpj,
//! }
//!
//! fn main() {
//! let company1 = Company {
//! name: "ACME",
//! cnpj: Cnpj::generate(),
//! };
//!
//! // Serializes the struct into JSON
//! let json = serde_json::to_string(&company1).unwrap();
//! println!("{}", json);
//!
//! // Deserializes the struct back
//! let company2: Company = serde_json::from_str(&json).unwrap();
//! assert_eq!(company1, company2);
//! }
//! ```
#![warn(clippy::all)]
mod cnpj;
mod cpf;
pub use crate::cpf::*;
pub type Icn = Cpf;
pub use crate::cnpj::*;