pub struct Cpf(/* private fields */);
Expand description
A valid CPF number. Parsing recognizes numbers with or without separators (dot, minus, and slash).
Implementations§
Source§impl Cpf
impl Cpf
Sourcepub fn from_slice(slice: &[u8]) -> Result<Self, ParseCpfError>
pub fn from_slice(slice: &[u8]) -> Result<Self, ParseCpfError>
Parses a byte slice of numbers as an CPF, guessing the missing parts.
§Examples
Basic usage:
use brids::Cpf;
match Cpf::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 9]) {
Ok(cpf) => println!("{cpf} is a valid number."),
Err(err) => eprintln!("Error: {err}"),
}
Guess the check digits:
use brids::Cpf;
match Cpf::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9]) {
Ok(cpf) => println!("{cpf} is a valid number."),
Err(err) => eprintln!("Error: {err}"),
}
Sourcepub fn as_bytes(&self) -> &[u8; 11]
pub fn as_bytes(&self) -> &[u8; 11]
Returns a byte slice of the numbers.
§Examples
use brids::Cpf;
let cpf = "123.456.789-09".parse::<Cpf>().expect("Invalid CPF");
let digits = cpf.as_bytes();
Sourcepub fn generate() -> Self
pub fn generate() -> Self
Generates a random number, using rand::thread_rng
(requires std
and rand
features).
To use a different generator, instantiate the generator directly.
§Examples
use brids::Cpf;
let cpf = Cpf::generate();
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Cpf
impl<'de> Deserialize<'de> for Cpf
Source§fn 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
Source§impl Distribution<Cpf> for Standard
impl Distribution<Cpf> for Standard
Source§impl Ord for Cpf
impl Ord for Cpf
Source§impl PartialOrd for Cpf
impl PartialOrd for Cpf
impl Copy for Cpf
impl Eq for Cpf
impl StructuralPartialEq for Cpf
Auto Trait Implementations§
impl Freeze for Cpf
impl RefUnwindSafe for Cpf
impl Send for Cpf
impl Sync for Cpf
impl Unpin for Cpf
impl UnwindSafe for Cpf
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more