pub struct NHSNumberString(pub NHSNumber);Expand description
Newtype that serialises the wrapped NHSNumber as its canonical
"DDD DDD DDDD" string and deserialises via the crate’s
FromStr parser.
The inner value is a public tuple field, so wrapping and unwrapping are plain constructor / field syntax:
use nhs_number::NHSNumber;
use nhs_number::serde_string::NHSNumberString;
let n = NHSNumber::new([9, 9, 9, 1, 0, 0, 0, 0, 0, 3]);
let wrapped = NHSNumberString(n);
let unwrapped: NHSNumber = wrapped.0;
assert_eq!(unwrapped, n);From conversions are provided in both directions:
use nhs_number::NHSNumber;
use nhs_number::serde_string::NHSNumberString;
let n = NHSNumber::new([9, 9, 9, 1, 0, 0, 0, 0, 0, 3]);
let wrapped = NHSNumberString::from(n);
let back = NHSNumber::from(wrapped);
assert_eq!(back, n);Deserialisation accepts both documented input shapes and rejects
everything else, exactly like FromStr:
use nhs_number::serde_string::NHSNumberString;
let tight: NHSNumberString = serde_json::from_str(r#""9991000003""#).unwrap();
let canonical: NHSNumberString = serde_json::from_str(r#""999 100 0003""#).unwrap();
assert_eq!(tight, canonical);
assert!(serde_json::from_str::<NHSNumberString>(r#""999-100-0003""#).is_err());Tuple Fields§
§0: NHSNumberTrait Implementations§
Source§impl Clone for NHSNumberString
impl Clone for NHSNumberString
Source§fn clone(&self) -> NHSNumberString
fn clone(&self) -> NHSNumberString
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for NHSNumberString
Source§impl Debug for NHSNumberString
impl Debug for NHSNumberString
Source§impl<'de> Deserialize<'de> for NHSNumberString
Deserialise from a string via FromStr.
impl<'de> Deserialize<'de> for NHSNumberString
Deserialise from a string via FromStr.
Accepts exactly the two documented shapes; the error message for a rejected string never includes the string itself.
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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 NHSNumberString
Delegates to the wrapped NHSNumber’s canonical form.
impl Display for NHSNumberString
Delegates to the wrapped NHSNumber’s canonical form.
impl Eq for NHSNumberString
Source§impl From<NHSNumber> for NHSNumberString
impl From<NHSNumber> for NHSNumberString
Source§impl From<NHSNumberString> for NHSNumber
impl From<NHSNumberString> for NHSNumber
Source§fn from(w: NHSNumberString) -> Self
fn from(w: NHSNumberString) -> Self
Converts to this type from the input type.
Source§impl FromStr for NHSNumberString
Delegates to the wrapped NHSNumber’s parser.
impl FromStr for NHSNumberString
Delegates to the wrapped NHSNumber’s parser.
Source§impl Hash for NHSNumberString
impl Hash for NHSNumberString
Source§impl Ord for NHSNumberString
impl Ord for NHSNumberString
Source§fn cmp(&self, other: &NHSNumberString) -> Ordering
fn cmp(&self, other: &NHSNumberString) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for NHSNumberString
impl PartialEq for NHSNumberString
Source§impl PartialOrd for NHSNumberString
impl PartialOrd for NHSNumberString
Source§impl Serialize for NHSNumberString
Serialise as the canonical twelve-character string (spec/05-string-forms.md §5.1).
impl Serialize for NHSNumberString
Serialise as the canonical twelve-character string (spec/05-string-forms.md §5.1).
impl StructuralPartialEq for NHSNumberString
Auto Trait Implementations§
impl Freeze for NHSNumberString
impl RefUnwindSafe for NHSNumberString
impl Send for NHSNumberString
impl Sync for NHSNumberString
impl Unpin for NHSNumberString
impl UnsafeUnpin for NHSNumberString
impl UnwindSafe for NHSNumberString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more