[][src]Struct pesel::pesel::PESEL

pub struct PESEL { /* fields omitted */ }

Methods

impl PESEL[src]

pub fn new(
    year: u16,
    month: u8,
    day: u8,
    pesel_gender: PeselGender
) -> Result<PESEL, PeselError>
[src]

Tries to create new PESEL strucutre based on:

  • birth date (could be in the future!)
  • biological gender

Returns Result<PESEL, PeselError> When PeselError is returned it is mainly due to the fact that provided date of birth is invalid: for example 30th of February, 31st of April etc., or date is out range for PESEL (earlier than 1800 or after 2299)

Example:

use pesel::pesel::{PESEL as PESEL, PeselGender};

// some code here...

let result = PESEL::new(1981, 05, 29, PeselGender::Female);
match result {
    Ok(pesel) => println!("generated PESEL: {}", pesel),
    _ => println!("unable to create PESEL for specified date"),
}

Returned PESEL structure is valid (i.e. passes validation algorithm check - new_pesel.is_valid should always return true

impl PESEL[src]

pub fn is_valid(&self) -> bool[src]

Checks if PESEL number is properly generated - i.e. if algorithmic check on all fields is equal to checksum (which is a part of PESEL number)

PESEL validation algorithm is as follows:

  1. PESEL number is 11 digits, last one is checksum. This gives 10 digits.
  2. The digits are usually called a, b, c, d, e, f, g, h, i, j
  3. First step is to calculate special sum of all digits except checksum as follows: 9a + 7b + 3c + d + 9e + 7f + 3g + h + 9i + 7j
  4. The sum calculated above modulo 10 should be equal to checksum

Please note that some PESEL numbers that are in use in Poland are not properly generated, and thus this check may fail for a PESEL number that is officially used. Note: this value is precomputed

pub fn gender(&self) -> PeselGender[src]

Returns biological gender as PeselGender enum

pub fn date_of_birth(&self) -> Date<Local>[src]

Returns date of birth as chrono::Date

pub fn gender_name(&self) -> String[src]

pub fn pesel_number(&self) -> String[src]

Trait Implementations

impl Debug for PESEL[src]

impl Display for PESEL[src]

impl FromStr for PESEL[src]

type Err = PeselError

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self, Self::Err>[src]

This method implements parsing 11 character long string, containing only digits into PESEL number. There are some checks performed:

  • length of the string provided (11 characters)
  • all characters have to be digits
  • birth year must be between 1800 and 2299
  • day should not exceed 31
  • month should be of range 1..12

Important note: as this function could be used to build a PESEL structure retrieved from database - no algorithm validity check against PESEL number is performed. This is due to the fact that some PESEL numbers in use were not generated correctly (but are recognized by State as valid ones).

Example of use:

use std::str::FromStr;
use pesel::pesel::{PESEL as PESEL, PeselGender};

// some code here...

let pesel_number ="44051401458".to_string();
let pesel = PESEL::from_str(pesel_number.as_str());
match pesel {
Ok(t) => println!("{}", t),
_ => panic!("invalid PESEL provided")
}

In case an error occrus PeselError with apropriate message is being returned. This may happen when:

  • string is not of expected length (11 characters)
  • not all characters inside string are digits
  • year of birth is out of range
  • birth date is incorrect (i.e. 30th of February, 31st of April...

Auto Trait Implementations

impl RefUnwindSafe for PESEL

impl Send for PESEL

impl Sync for PESEL

impl Unpin for PESEL

impl UnwindSafe for PESEL

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,