CodiceFiscale

Struct 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

Source

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

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
Source

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
Source

pub fn get_codice(&self) -> &str

Returns the codice fiscale

Source

pub fn get_person_data(&self) -> &PersonData

Returns the person data

Source

pub fn is_name_valid(&self, name: &str) -> bool

Check if the given name is valid for this fiscal code

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CodiceFiscale

Source§

fn eq(&self, other: &CodiceFiscale) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CodiceFiscale

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.