NHSNumber

Struct NHSNumber 

Source
pub struct NHSNumber {
    pub digits: [i8; 10],
}
Expand description

NHS Number is a unique identifier for patients in the National Health Service of England, Wales, and the Isle of Man.

Reference:

use nhs_number::NHSNumber;
let digits = [9, 9, 9, 1, 2, 3, 4, 5, 6, 0];
let nhs_number = NHSNumber { digits: digits };

Fields§

§digits: [i8; 10]

Implementations§

Source§

impl NHSNumber

Source

pub fn new(digits: [i8; 10]) -> Self

Create a new NHS Number instance with the provided digits.

Example:

use nhs_number::NHSNumber;
let digits = [9, 9, 9, 1, 2, 3, 4, 5, 6, 0];
let nhs_number = NHSNumber::new(digits);
Source

pub fn check_digit(&self) -> i8

Get the NHS Number check digit i.e. the last digit.

Example:

use nhs_number::NHSNumber;
let digits = [9, 9, 9, 1, 2, 3, 4, 5, 6, 0];
let nhs_number = NHSNumber::new(digits);
let check_digit = nhs_number.check_digit();
assert_eq!(check_digit, 0);

This method calls the function check_digit().

Source

pub fn calculate_check_digit(&self) -> i8

Calculate the NHS Number check digit using a checksum algorithm.

Example:

use nhs_number::NHSNumber;
let digits = [9, 9, 9, 1, 2 , 3, 4, 5, 6, 0];
let nhs_number = NHSNumber::new(digits);
let check_digit = nhs_number.calculate_check_digit();
assert_eq!(check_digit, 0);

This method calls the function calculate_check_digit().

Source

pub fn validate_check_digit(&self) -> bool

Validate the NHS Number check digit equals the calculated check digit.

Example:

use nhs_number::NHSNumber;
let digits = [9, 9, 9, 1, 2, 3, 4, 5, 6, 0];
let nhs_number = NHSNumber::new(digits);
let is_valid = nhs_number.validate_check_digit();
assert_eq!(is_valid, true);

This method calls the function validate_check_digit().

Source

pub fn testable_random_sample() -> NHSNumber

Generate a testable random sample NHS Number.

Example:

use nhs_number::{NHSNumber, testable::{TESTABLE_MIN, TESTABLE_MAX}};
let sample = NHSNumber::testable_random_sample();
assert!(sample >= *TESTABLE_MIN);
assert!(sample <= *TESTABLE_MAX);

This method calls the function testable_random_sample().

Trait Implementations§

Source§

impl Clone for NHSNumber

Source§

fn clone(&self) -> NHSNumber

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NHSNumber

Source§

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

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

impl<'de> Deserialize<'de> for NHSNumber

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 Display for NHSNumber

Format the NHS Number as a 10-digit number with spaces.

Example:

use nhs_number::NHSNumber;
let digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let nhs_number = NHSNumber::new(digits);
let nhs_number_string = nhs_number.to_string();
assert_eq!(nhs_number_string, "012 345 6789");

The NHS Number is formatted as a 10-digit number with spaces:

  • 3 digits
  • space
  • 3 digits
  • space
  • 4 digits

This method must be equivalent to the function format().

Source§

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

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

impl FromStr for NHSNumber

Implement the FromStr trait for NHSNumber to allow parsing from a string.

This parser allows for optional space separators in the NHS Number string, so long as the space separators are in their expected positions.

A valid NHS Number format can be either:

  • 10 digits e.g. “0123456789”

  • 12 characters with spaces e.g. “012 345 6789”.

Example:

use nhs_number::NHSNumber;
use std::str::FromStr;
let nhs_number_str = "012 345 6789";
let nhs_number: NHSNumber = NHSNumber::from_str(nhs_number_str).unwrap();
assert_eq!(nhs_number.digits, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Into<String> for NHSNumber

Convert the NHSNumber into a String.

Example:

use nhs_number::NHSNumber;
let digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let nhs_number = NHSNumber::new(digits);
let nhs_number_string: String = nhs_number.into();
assert_eq!(nhs_number_string, "012 345 6789");
Source§

fn into(self) -> String

Converts this type into the (usually inferred) input type.
Source§

impl Ord for NHSNumber

Source§

fn cmp(&self, other: &NHSNumber) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for NHSNumber

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for NHSNumber

Source§

fn partial_cmp(&self, other: &NHSNumber) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for NHSNumber

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 Copy for NHSNumber

Source§

impl Eq for NHSNumber

Source§

impl StructuralPartialEq for NHSNumber

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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