Struct codice_fiscale::CodiceFiscale
source · pub struct CodiceFiscale { /* private fields */ }
Expand description
Codice fiscale calculation and parsing. The static method check()
is most likely what you need.
Note: the PartialEq trait here supposes every PersonData and CodiceFiscaleParts fields are equal,
which actually makes for identical persons and not only identical codice fiscale.
For comparison you might be better just comparing what is returned by codice()
method.
Implementations§
source§impl CodiceFiscale
impl CodiceFiscale
sourcepub fn check(codice: &str) -> Result<(), Error>
pub fn check(codice: &str) -> Result<(), Error>
Static method returns true if codice fiscale is valid, false otherwise. Behind the scenes,
it calls parse()
and returns Ok(()) in case of errors, the Error otherwise.
This is the method almost everybody will use.
Examples
use codice_fiscale::*;
if CodiceFiscale::check("BLTMHL77S04E889G").is_ok() {
println!("Codice is OK!");
}
sourcepub fn new(initdata: &PersonData) -> Result<CodiceFiscale, Error>
pub fn new(initdata: &PersonData) -> Result<CodiceFiscale, Error>
Constructor which creates a CodiceFiscale struct from personal data, which has to be provided as a PersonData struct
Examples
use codice_fiscale::*;
match CodiceFiscale::new(&PersonData {
name : "Michele".to_string(),
surname : "Beltrame".to_string(),
birthdate : "1977-11-04".to_string(),
gender : Gender::M,
place_of_birth : BELFIORE_STORE.get_info("Rovigo").unwrap().clone(),
}) {
Ok(cf) => println!("CF is: {}", cf.get_codice()),
Err(e) => println!("Some data was invalid: {:?}", e),
}
Errors
- invalid-birthdate - not a valid YYYY-MM-DD date
- invalid-belfiore-code - the place was not found in the database
sourcepub fn parse(codice: &str) -> Result<CodiceFiscale, Error>
pub fn parse(codice: &str) -> Result<CodiceFiscale, Error>
Constructor which creates a CodiceFiscale struct from a codice fiscale string
Examples
use codice_fiscale::*;
match CodiceFiscale::parse("BLTMHL77S04E889G") {
Ok(cf) => println!("CF is OK, birthdate is: {}", cf.get_person_data().birthdate),
Err(e) => println!("Codice is invalid beacuse: {:?}", e),
}
Errors
You will usually get one of the first two errors: if the checkchar matches, it’s very difficult for the codice fiscale to be incorrect, except if it was messed up on purpose.
- invalid-length - not 16 chars
- invalid-checkchar - final check char is not correct
- invalid-surname - not a 3-chars surname
- invalid-name - not a 3-chars name
- invalid-birthyear
- invalid-birthmonth
- invalid-birthdate
- invalid-belfiore-code
sourcepub fn get_codice(&self) -> &str
pub fn get_codice(&self) -> &str
Returns the codice fiscale
sourcepub fn get_person_data(&self) -> &PersonData
pub fn get_person_data(&self) -> &PersonData
Returns the person data
sourcepub fn is_name_valid(&self, name: &str) -> bool
pub fn is_name_valid(&self, name: &str) -> bool
Check if the given name is valid for this fiscal code
sourcepub fn is_surname_valid(&self, surname: &str) -> bool
pub fn is_surname_valid(&self, surname: &str) -> bool
Check if the given surname is valid for this fiscal code
Trait Implementations§
source§impl Debug for CodiceFiscale
impl Debug for CodiceFiscale
source§impl PartialEq<CodiceFiscale> for CodiceFiscale
impl PartialEq<CodiceFiscale> for CodiceFiscale
source§fn eq(&self, other: &CodiceFiscale) -> bool
fn eq(&self, other: &CodiceFiscale) -> bool
self
and other
values to be equal, and is used
by ==
.