pub struct Cnpj(_);
Expand description
A valid CNPJ number. Parsing recognizes numbers with or without separators (dot, minus, slash, and space).
Implementations
sourceimpl Cnpj
impl Cnpj
sourcepub fn from_slice(slice: &[u8]) -> Result<Self, ParseCnpjError>
pub fn from_slice(slice: &[u8]) -> Result<Self, ParseCnpjError>
Parses a byte slice of numbers as an CNPJ, guessing the missing parts.
Examples
Basic usage:
use brids::Cnpj;
match Cnpj::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 1, 9, 5]) {
Ok(cnpj) => println!("{} is a valid number.", cnpj),
Err(err) => println!("Error: {}", err),
}
Guess the check digits:
use brids::Cnpj;
match Cnpj::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 2, 7]) {
Ok(cnpj) => println!("{} is a valid number.", cnpj),
Err(err) => println!("Error: {}", err),
}
Guess the branch and check digits:
use brids::Cnpj;
match Cnpj::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8]) {
Ok(cnpj) => println!("{} is a valid number.", cnpj),
Err(err) => println!("Error: {}", err),
}
sourcepub fn as_bytes(&self) -> &[u8; 14]
pub fn as_bytes(&self) -> &[u8; 14]
Returns a byte slice of the numbers.
Examples
use brids::Cnpj;
let cnpj = Cnpj::generate();
let bytes = cnpj.as_bytes();
sourcepub fn branch(&self) -> u16
pub fn branch(&self) -> u16
Returns the entity branch.
Examples
use brids::Cnpj;
let cnpj = Cnpj::generate();
let branch = cnpj.branch();
sourcepub fn generate() -> Self
pub fn generate() -> Self
Generates a random number, using rand::thread_rng
(optional dependency enabled by
default). To use a different generator, instantiate the generator directly.
Examples
use brids::Cnpj;
let cnpj = Cnpj::generate();
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Cnpj
impl<'de> Deserialize<'de> for Cnpj
sourcefn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Distribution<Cnpj> for Standard
impl Distribution<Cnpj> for Standard
sourceimpl Ord for Cnpj
impl Ord for Cnpj
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialOrd<Cnpj> for Cnpj
impl PartialOrd<Cnpj> for Cnpj
sourcefn partial_cmp(&self, other: &Cnpj) -> Option<Ordering>
fn partial_cmp(&self, other: &Cnpj) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Cnpj
impl Eq for Cnpj
impl StructuralEq for Cnpj
impl StructuralPartialEq for Cnpj
Auto Trait Implementations
impl RefUnwindSafe for Cnpj
impl Send for Cnpj
impl Sync for Cnpj
impl Unpin for Cnpj
impl UnwindSafe for Cnpj
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more