Function slk581::encode [] [src]

pub fn encode<'a>(
    family_name: Option<&str>,
    given_name: Option<&str>,
    date_of_birth: Option<&str>,
    sex: Option<&'a str>
) -> Result<String, SLK581Error<'a>>

This function encodes given family name, given name, date of birth and sex in XXXZZDDMMYYYYN sequence.

Errors

Returns UnknownDateOfBirth when date of birth not provided:

use slk581::encode;
use slk581::SLK581Error;
use slk581::SLK581Error::UnknownDateOfBirth;

let encoded_result: Result<String, SLK581Error> = encode(None, None, None, None);
assert_eq!(encoded_result.is_err(), true);
assert_eq!(encoded_result.unwrap_err(), UnknownDateOfBirth);

Returns InvalidDateOfBirth when date of birth provided in invalid format:

use slk581::encode;
use slk581::SLK581Error;
use slk581::SLK581Error::InvalidDateOfBirth;

let date_of_birth: Option<&str> = Some("20001219");
let encoded_result: Result<String, SLK581Error> = encode(None, None, date_of_birth, None);
assert_eq!(encoded_result.is_err(), true);
assert_eq!(encoded_result.unwrap_err(), InvalidDateOfBirth);

Returns UnsupportedSex when unsupported sex value provided:

use slk581::encode;
use slk581::SLK581Error;
use slk581::SLK581Error::UnsupportedSex;

let date_of_birth: Option<&str> = Some("2000-12-19");
let sex: Option<&str> = Some("test");
let encoded_result: Result<String, SLK581Error> = encode(None, None, date_of_birth, sex);
assert_eq!(encoded_result.is_err(), true);
assert_eq!(encoded_result.unwrap_err(), UnsupportedSex("test"));

Examples

use slk581::encode;
use slk581::SLK581Error;

let date_of_birth: Option<&str> = Some("2000-12-19");

let encoded_result: Result<String, SLK581Error> =
    encode(Some("Doe"), Some("John"), date_of_birth, Some("m"));
assert_eq!(encoded_result.is_ok(), true);
assert_eq!(encoded_result.unwrap(), "OE2OH191220001");

let encoded_result: Result<String, SLK581Error> =
    encode(Some("Smith"), Some("Jane"), date_of_birth, Some("f"));
assert_eq!(encoded_result.is_ok(), true);
assert_eq!(encoded_result.unwrap(), "MIHAN191220002");

let encoded_result: Result<String, SLK581Error> =
    encode(Some("O Bare"), Some("Foo"), date_of_birth, Some("t"));
assert_eq!(encoded_result.is_ok(), true);
assert_eq!(encoded_result.unwrap(), "BAEOO191220003");