Crates.io | pesel |
lib.rs | pesel |
version | 0.1.3 |
source | src |
created_at | 2019-07-24 22:15:12.602171 |
updated_at | 2020-03-29 18:52:22.980644 |
description | PESEL validation & generation library |
homepage | |
repository | https://github.com/MaciekTalaska/pesel |
max_upload_size | |
id | 151451 |
size | 38,902 |
PESEL
is a simple Rust library to validate PESEL numbers.
PESEL is national identification number used in Poland. Every citizen of Republic of Poland is assigned PESEL when being born (and since 2015 this should also apply to foreigners living in Poland for more than 2 months).
There are some interesting facts about the PESEL number - find more on Wikipedia
This library offers two main features:
a) creating PESEL from String (and performing some checks to make sure PESEL is valid)
use std::str::FromStr;
let pesel_number = "44051401458";
let result = PESEL::from_str(pesel_number);
match result {
Ok(pesel) => println!("PESEL: {}", pesel),
_ => println!("invalid PESEL provided"),
}
// alternatively, pass a string literal:
let result = PESEL::from_str("44051401458");
match result {
OK(pesel) => println!("PESEL: {}", pesel),
_ => println!("invalid PESEL string"),
}
b) generating PESEL number, based on date of birth of a person and their biological gender
let result = PESEL::new(1980, 05, 26, PeselGender::Male);
match result {
Ok(pesel) => println!("generated PESEL: {}", pesel),
_ => println!("unable to create PESEL for specified date"),
}
Note: behavior of this method changed. It used to return PESEL, now returns Result<PESEL, PeselParsingError>
. Errors are usually due to:
provided date of birth being out of range for PESEL (earlier than 1800, later than 2299)
provided date of birth is not valid i.e.: 30th of February, 31st of April...
Please note that after PESEL number structure is constructed there is no way to change it - it stays immutable forever.