Skip to main content

Wkn

Struct Wkn 

Source
pub struct Wkn { /* private fields */ }
Expand description

A validated Wertpapierkennnummer (WKN).

A Wkn can only be created by Wkn::parse (or the explicitly unchecked Wkn::from_bytes_unchecked), so a value of this type is a proof that the six characters form a structurally valid WKN. It stores the identifier inline as [u8; 6], is Copy, and allocates nothing.

§Examples

use regit_identifiers::Wkn;

let wkn = Wkn::parse("A1EWWW").unwrap();
assert_eq!(wkn.as_str(), "A1EWWW");
assert!(!wkn.is_numeric());

Implementations§

Source§

impl Wkn

Source

pub const LENGTH: usize = 6

The number of characters in a WKN.

Source

pub fn parse(s: &str) -> Result<Self, ValidationError>

Parses and fully validates a WKN.

Validation is strict and, in order: the input must be exactly 6 characters; each character must be an ASCII digit or an upper-case letter, with I and O excluded. A WKN has no check digit, so a structurally valid string is always accepted.

§Errors
§Examples
use regit_identifiers::Wkn;
use regit_identifiers::errors::ValidationError;

assert!(Wkn::parse("766403").is_ok());

// A literal `I` is rejected, not silently accepted.
assert_eq!(
    Wkn::parse("A1IWWW"),
    Err(ValidationError::InvalidCharacter { position: 3, found: 'I' }),
);
Source

pub fn validate(s: &str) -> Result<(), ValidationError>

Validates a WKN without constructing one.

Equivalent to Wkn::parse(s).map(|_| ()); use it when only the verdict is needed.

§Errors

Returns the same ValidationError variants as Wkn::parse.

§Examples
use regit_identifiers::Wkn;

assert!(Wkn::validate("519000").is_ok());
assert!(Wkn::validate("A1IWWW").is_err());
Source

pub const fn from_bytes_unchecked(bytes: [u8; 6]) -> Self

Wraps 6 raw bytes as a Wkn without any validation.

The caller asserts that bytes holds the 6 ASCII characters of a valid WKN. This exists for reconstructing a Wkn from bytes that were validated earlier; prefer Wkn::parse for any untrusted input.

§Examples
use regit_identifiers::Wkn;

let wkn = Wkn::from_bytes_unchecked(*b"A1EWWW");
assert_eq!(wkn.as_str(), "A1EWWW");
Source

pub fn as_str(&self) -> &str

Returns the WKN as a string slice.

§Examples
use regit_identifiers::Wkn;

assert_eq!(Wkn::parse("766403").unwrap().as_str(), "766403");
Source

pub fn as_bytes(&self) -> &[u8]

Returns the WKN as its 6 raw ASCII bytes.

§Examples
use regit_identifiers::Wkn;

assert_eq!(Wkn::parse("766403").unwrap().as_bytes(), b"766403");
Source

pub fn is_numeric(&self) -> bool

Returns true if all six characters are ASCII digits.

A purely numeric WKN is a legacy identifier; alphanumeric WKNs were introduced once the numeric space began to run out.

§Examples
use regit_identifiers::Wkn;

assert!(Wkn::parse("766403").unwrap().is_numeric());
assert!(!Wkn::parse("A1EWWW").unwrap().is_numeric());

Trait Implementations§

Source§

impl AsRef<str> for Wkn

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Wkn

Source§

fn clone(&self) -> Wkn

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

Source§

impl Debug for Wkn

Source§

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

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

impl Display for Wkn

Source§

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

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

impl Eq for Wkn

Source§

impl FromStr for Wkn

Source§

type Err = ValidationError

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 Hash for Wkn

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Wkn

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Wkn

Auto Trait Implementations§

§

impl Freeze for Wkn

§

impl RefUnwindSafe for Wkn

§

impl Send for Wkn

§

impl Sync for Wkn

§

impl Unpin for Wkn

§

impl UnsafeUnpin for Wkn

§

impl UnwindSafe for Wkn

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, 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.