GithubHelp home page GithubHelp logo

maciektalaska / pesel Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 101 KB

simple PESEL validator library written in Rust

Rust 100.00%
rust-library rust-crate pesel pesel-validation pesel-validator pesel-number rust

pesel's Introduction

Travis Build Status AppVeyor Build status

PESEL is a simple Rust library to validate PESEL numbers.

What is PESEL number?

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

Usage & Examples

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.

TODO

  • validate date before PESEL is created to avoid creation of PESEL for invalid date (31st of February, 31st of April, 31st of June...)
  • validate PESEL numbers in bulk (ideally: reading from file)

pesel's People

Contributors

maciektalaska avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.