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§

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!");
}

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

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

Returns the codice fiscale

Returns the person data

Check if the given name is valid for this fiscal code

Check if the given surname is valid for this fiscal code

Trait Implementations§

Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.