Skip to main content

Cnpj

Struct Cnpj 

Source
pub struct Cnpj { /* private fields */ }
Expand description

A validated CNPJ stored as 14 ASCII bytes.

Positions 0-11 may contain 0-9 or A-Z (alphanumeric CNPJ). Positions 12-13 are always numeric digits (check digits).

use stdbr_core::cnpj::{Cnpj, CnpjKind, generate_cnpj};

let cnpj = generate_cnpj(CnpjKind::Numeric);
assert_eq!(cnpj.as_str().len(), 14);
assert_eq!(cnpj.to_string().len(), 18); // XX.XXX.XXX/XXXX-DD

let parsed: Cnpj = cnpj.to_string().parse().unwrap();
assert_eq!(cnpj, parsed);

Implementations§

Source§

impl Cnpj

Source

pub fn as_str(&self) -> &str

Unformatted 14-character &str.

Source

pub fn kind(&self) -> CnpjKind

Whether the CNPJ is numeric or alphanumeric.

Source

pub fn raiz(&self) -> &str

Root (positions 1-8): identifies the company.

Source

pub fn ordem(&self) -> &str

Order (positions 9-12): identifies the establishment.

Source

pub fn establishment_type(&self) -> EstablishmentType

Whether this is Matriz (ordem == “0001”) or Filial.

Source

pub fn check_digits(&self) -> (u8, u8)

The two check digits (d1, d2) as numeric values.

Source

pub fn masked(&self) -> String

Masked: XX.XXX.XXX/****-**.

Trait Implementations§

Source§

impl AsRef<str> for Cnpj

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Cnpj

Source§

fn clone(&self) -> Cnpj

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Cnpj

Source§

impl Debug for Cnpj

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Cnpj

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Cnpj

Source§

impl FromStr for Cnpj

Source§

type Err = CnpjError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Cnpj

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Cnpj

Source§

fn eq(&self, other: &Cnpj) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Cnpj

Auto Trait Implementations§

§

impl Freeze for Cnpj

§

impl RefUnwindSafe for Cnpj

§

impl Send for Cnpj

§

impl Sync for Cnpj

§

impl Unpin for Cnpj

§

impl UnsafeUnpin for Cnpj

§

impl UnwindSafe for Cnpj

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.