Skip to main content

PassportBook

Struct PassportBook 

Source
pub struct PassportBook {
    pub country: String,
    pub number: String,
    pub issued: Option<NaiveDate>,
    pub expires: Option<NaiveDate>,
}
Expand description

A passport book — country of issue, book number, and optional effective date range.

Passport data has three properties that make it a poor fit for the crate’s per-scheme Option<String> national-identifier pattern, and which this type captures explicitly:

  1. Scheme-local provenance. A passport book number is only meaningful alongside its issuing country. The book number "AB123456" issued by the United Kingdom is a different identifier from "AB123456" issued by the United States; the matcher MUST NOT cross-match them. Provenance lives on the PassportBook::country field, not on the field name.
  2. Multi-country. A single worker may hold passports from multiple countries simultaneously (dual / multiple citizenship). A Vec<PassportBook> lets a crate::Worker carry one entry per book without privileging any particular jurisdiction.
  3. Time-varying. When a passport is renewed, the new book has a different number; the old book number is no longer current but the worker is unchanged. Worker records may carry the current book, prior books, or both. Matching treats any shared (country, number) pair across the two records as evidence that the records refer to the same worker, regardless of issue date.

Construction via PassportBook::new canonicalises both the country (trimmed, uppercased; must be exactly 2 ASCII letters) and the number (whitespace stripped, letters uppercased) so two records carrying different textual layouts of the same book canonicalise to the same (country, number) key. Date fields are optional metadata and are not used in matching — they exist for downstream display and audit. Per-country structural validation is intentionally not performed; passport formats vary widely and a case+whitespace canonical form is sufficient for matching.

§Example

use worker_matcher::PassportBook;
use chrono::NaiveDate;

let book = PassportBook::new("gb", " 123 456 789 ")
    .expect("valid book")
    .with_issued(NaiveDate::from_ymd_opt(2020, 1, 1).unwrap())
    .with_expires(NaiveDate::from_ymd_opt(2030, 1, 1).unwrap());

assert_eq!(book.country, "GB");
assert_eq!(book.number,  "123456789");
assert!(book.issued.is_some());

// Rejection: country must be exactly 2 ASCII letters.
assert!(PassportBook::new("GBR", "123").is_none());
assert!(PassportBook::new("1A",  "123").is_none());
// Rejection: number must canonicalise to a non-empty string.
assert!(PassportBook::new("GB",  "   ").is_none());

Fields§

§country: String

ISO 3166-1 alpha-2 country code of issuance, uppercased.

§number: String

Passport book number, whitespace-stripped and uppercased.

§issued: Option<NaiveDate>

Optional issue date (not used in matching).

§expires: Option<NaiveDate>

Optional expiry date (not used in matching).

Implementations§

Source§

impl PassportBook

Source

pub fn new(country: impl AsRef<str>, number: impl AsRef<str>) -> Option<Self>

Construct a passport book, validating and canonicalising the country code (trimmed + uppercased; must be exactly 2 ASCII letters) and the book number (whitespace stripped + uppercased; must be non-empty after stripping).

Returns None for an invalid country code or an empty canonical number.

use worker_matcher::PassportBook;
let b = PassportBook::new("us", "abc 123 456").unwrap();
assert_eq!(b.country, "US");
assert_eq!(b.number,  "ABC123456");
Source

pub fn with_issued(self, date: NaiveDate) -> Self

Attach an issue date. The date is metadata only — it is NOT used in matching.

use worker_matcher::PassportBook;
use chrono::NaiveDate;
let b = PassportBook::new("GB", "123456789").unwrap()
    .with_issued(NaiveDate::from_ymd_opt(2020, 1, 1).unwrap());
assert!(b.issued.is_some());
Source

pub fn with_expires(self, date: NaiveDate) -> Self

Attach an expiry date. The date is metadata only — it is NOT used in matching.

use worker_matcher::PassportBook;
use chrono::NaiveDate;
let b = PassportBook::new("GB", "123456789").unwrap()
    .with_expires(NaiveDate::from_ymd_opt(2030, 1, 1).unwrap());
assert!(b.expires.is_some());

Trait Implementations§

Source§

impl Clone for PassportBook

Source§

fn clone(&self) -> PassportBook

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PassportBook

Source§

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

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

impl<'de> Deserialize<'de> for PassportBook

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for PassportBook

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for PassportBook

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for PassportBook

Source§

impl StructuralPartialEq for PassportBook

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,