pub struct CodiceFiscale { /* fields omitted */ }
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.
Static method returns true if codice fiscale is valid, false otherwise. Behind the scenes,
it calls parse()
and returns false in case of errors, true otherwise.
This is the method almost everybody will use.
use codice_fiscale::*;
if CodiceFiscale::check("BLTMHL77S04E889G") == true {
println!("Codice is OK!");
}
Constructor which creates a CodiceFiscale struct from personal data,
which has to be provided as a PersonData struct
use codice_fiscale::*;
match CodiceFiscale::new(&PersonData {
name : "Michele".to_string(),
surname : "Beltrame".to_string(),
birthdate : "1977-11-04".to_string(),
gender : Gender::M,
belfiore : "E889".to_string(),
}) {
Ok(cf) => println!("CF is: {}", cf.codice()),
Err(e) => println!("Some data was invalid: {:?}", e),
}
- invalid-birthdate - not a valid YYYY-MM-DD date
- invalid-belfiore-code - only check structure: letter + 3 digits
Constructor which creates a CodiceFiscale struct from a codice fiscale string
use codice_fiscale::*;
match CodiceFiscale::parse("BLTMHL77S04E889G") {
Ok(cf) => println!("CF is OK, birthdate is: {}", cf.persondata().birthdate),
Err(e) => println!("Codice is invalid beacuse: {:?}", e),
}
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
Returns the codice fiscale
Formats the value using the given formatter. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.