pub struct Cpf(_);
Expand description
A valid CPF/ICN number. Parsing recognizes numbers with or without separators (dot, minus, slash, and space).
Implementations
sourceimpl 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!("{} is a valid number.", cpf),
Err(err) => println!("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!("{} is a valid number.", cpf),
Err(err) => println!("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 = Cpf::generate();
let bytes = cpf.as_bytes();
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::Cpf;
let cpf = Cpf::generate();
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Cpf
impl<'de> Deserialize<'de> for Cpf
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<Cpf> for Standard
impl Distribution<Cpf> for Standard
sourceimpl Ord for Cpf
impl Ord for Cpf
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<Cpf> for Cpf
impl PartialOrd<Cpf> for Cpf
sourcefn partial_cmp(&self, other: &Cpf) -> Option<Ordering>
fn partial_cmp(&self, other: &Cpf) -> 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 Cpf
impl Eq for Cpf
impl StructuralEq for Cpf
impl StructuralPartialEq for Cpf
Auto Trait Implementations
impl RefUnwindSafe for Cpf
impl Send for Cpf
impl Sync for Cpf
impl Unpin for Cpf
impl UnwindSafe for Cpf
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