Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update docs #19

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl fmt::Display for PersonnummerError {
impl Error for PersonnummerError {}

#[allow(dead_code)]
/// Personnummer holds relevant data to check for valid personal identity numbers.
/// [Personnummer] holds relevant data to check for valid personal identity numbers.
pub struct Personnummer {
date: chrono::NaiveDate,
serial: u32,
Expand All @@ -52,7 +52,7 @@ pub struct Personnummer {
coordination: bool,
}

/// FormattedPersonnummer holds two formats of a normalized personal identity number, one long and
/// [FormattedPersonnummer] holds two formats of a normalized personal identity number, one long and
/// one short format. The long format displays the full century while the short format only
/// displays the year.
pub struct FormattedPersonnummer {
Expand All @@ -61,12 +61,12 @@ pub struct FormattedPersonnummer {
}

impl FormattedPersonnummer {
/// Returns the long format of a formatted personal identity number as a String.
/// Returns the long format of a formatted personal identity number as a [String].
pub fn long(&self) -> String {
self.long.clone()
}

/// Returns the short format of a formatted personal identity number as a String.
/// Returns the short format of a formatted personal identity number as a [String].
pub fn short(&self) -> String {
self.short.clone()
}
Expand Down Expand Up @@ -127,19 +127,19 @@ impl TryFrom<&str> for Personnummer {
}

impl Personnummer {
/// Returns a new instance of a Personnummer. Panics for invalid dates but not for invalid
/// personal identity numbers. Use valid() to check validity.
/// Returns a new instance of a [Personnummer]. Panics for invalid dates but not for invalid
/// personal identity numbers. Use [Personnummer::valid()] to check validity.
pub fn new(pnr: &str) -> Result<Personnummer, PersonnummerError> {
Personnummer::try_from(pnr)
}

/// Same as new() but returns an Option instead of panicing on invalid dates.
/// Same as [Personnummer::new()] but returns an [Option] instead of panicing on invalid dates.
pub fn parse(pnr: &str) -> Result<Personnummer, PersonnummerError> {
Personnummer::try_from(pnr)
}

/// Returns a FormattedPersonnummer from a Personnummer which can be used to display a
/// normalized version of the Personnummer.
/// Returns a [FormattedPersonnummer] from a [Personnummer] which can be used to display a
/// normalized version of the [Personnummer].
pub fn format(&self) -> FormattedPersonnummer {
let day = self.date.day();
let day_or_coordination = if self.coordination {
Expand All @@ -162,7 +162,7 @@ impl Personnummer {
FormattedPersonnummer { long, short }
}

/// Validate a Personnummer. The validation requires a valid date and that the Luhn checksum
/// Validate a [Personnummer]. The validation requires a valid date and that the Luhn checksum
/// matches the control digit.
pub fn valid(&self) -> bool {
let ymd = format!(
Expand Down Expand Up @@ -206,17 +206,17 @@ impl Personnummer {
self.coordination
}

/// Year of date of birth.
/// Year of birth date.
pub fn year(&self) -> i32 {
self.date.year()
}

/// Month of date of birth.
/// Month of birth date.
pub fn month(&self) -> u32 {
self.date.month()
}

/// Day of date of birth.
/// Day of birth date.
pub fn day(&self) -> u32 {
self.date.day()
}
Expand Down