Struct cnpj::Cnpj[][src]

pub struct Cnpj { /* fields omitted */ }

A valid CNPJ number.

Initialize a Cnpj from a &str or an array of digits:

use cnpj::Cnpj;

let cnpj1 = "96.769.900/0001-77".parse::<Cnpj>()?;
let cnpj2 = Cnpj::try_from([9, 6, 7, 6, 9, 9, 0, 0, 0, 0, 0, 1, 7, 7])?;
assert_eq!(cnpj1, cnpj2);

Note that the Cnpj struct can only be initialized after a successfully parse, so it is guaranteed to always be valid.

use cnpj::Cnpj;

let cnpj = "00.000.000/0000-00".parse::<Cnpj>();
assert!(cnpj.is_err());

Implementations

impl Cnpj[src]

pub fn digits(&self) -> &[u8; 14][src]

The Cnpj digits.

use cnpj::Cnpj;

let cnpj: Cnpj = "96.769.900/0001-77".parse()?;
assert_eq!(cnpj.digits(), &[9, 6, 7, 6, 9, 9, 0, 0, 0, 0, 0, 1, 7, 7]);

pub fn formatted(&self) -> ArrayString<18>[src]

Formats a Cnpj number.

use cnpj::Cnpj;

let cnpj: Cnpj = "96769900000177".parse()?;
assert_eq!(cnpj.formatted().as_str(), "96.769.900/0001-77");

Note that numbers with less than 14 digits will be padded by zeros.

use cnpj::Cnpj;

let cnpj: Cnpj = "1.219.900/0001-97".parse()?;
assert_eq!(cnpj.formatted().as_str(), "01.219.900/0001-97");

Trait Implementations

impl Clone for Cnpj[src]

impl Copy for Cnpj[src]

impl Debug for Cnpj[src]

impl Display for Cnpj[src]

impl Eq for Cnpj[src]

impl FromStr for Cnpj[src]

type Err = ParseCnpjError

The associated error which can be returned from parsing.

impl Hash for Cnpj[src]

impl PartialEq<Cnpj> for Cnpj[src]

impl StructuralEq for Cnpj[src]

impl StructuralPartialEq for Cnpj[src]

impl TryFrom<&'_ str> for Cnpj[src]

type Error = ParseCnpjError

The type returned in the event of a conversion error.

impl TryFrom<[u8; 14]> for Cnpj[src]

type Error = ParseCnpjError

The type returned in the event of a conversion error.

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,