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
impl Wkn
Sourcepub fn parse(s: &str) -> Result<Self, ValidationError>
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
ValidationError::WrongLengthif the input is not 6 characters.ValidationError::InvalidCharacterif a character is not an ASCII digit or upper-case letter, or is a literalIorO(this also rejects lower-case input and any non-ASCII character).
§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' }),
);Sourcepub fn validate(s: &str) -> Result<(), ValidationError>
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());Sourcepub const fn from_bytes_unchecked(bytes: [u8; 6]) -> Self
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");Sourcepub fn as_str(&self) -> &str
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");Sourcepub fn as_bytes(&self) -> &[u8]
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");Sourcepub fn is_numeric(&self) -> bool
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());