pub struct Cfi { /* private fields */ }Expand description
A validated Classification of Financial Instruments code (ISO 10962).
A Cfi can only be created by Cfi::parse (or the explicitly unchecked
Cfi::from_bytes_unchecked), so a value of this type is a proof that
the 6 characters are all upper-case letters and that the first is a
recognised ISO 10962 category letter. It stores the code inline as
[u8; 6], is Copy, and allocates nothing.
§Examples
use regit_identifiers::Cfi;
let cfi = Cfi::parse("ESVUFR").unwrap();
assert_eq!(cfi.category(), 'E');
assert_eq!(cfi.category_name(), "Equities");
assert_eq!(cfi.group(), 'S');
assert_eq!(cfi.attributes(), "VUFR");
assert_eq!(cfi.as_str(), "ESVUFR");Implementations§
Source§impl Cfi
impl Cfi
Sourcepub fn parse(s: &str) -> Result<Self, ValidationError>
pub fn parse(s: &str) -> Result<Self, ValidationError>
Parses and validates a CFI code.
Validation is strict and, in order: the input must be exactly 6
characters; every character must be an ASCII upper-case letter; and
the first character must be one of the 14 ISO 10962 category letters
E C D R O F S H I J K L T M. A CFI has no check digit, so any
6-letter string satisfying those rules parses.
The group character and the four attribute characters are not validated against the per-category ISO 10962 tables — see the module documentation for why.
§Errors
ValidationError::WrongLengthif the input is not 6 characters.ValidationError::InvalidCharacterif a character is not an ASCII upper-case letter (this also rejects digits, lower-case input, and any non-ASCII character).ValidationError::Structureif the first character is not a recognised ISO 10962 category letter.
§Examples
use regit_identifiers::Cfi;
use regit_identifiers::errors::ValidationError;
assert!(Cfi::parse("ESVUFR").is_ok());
// `Q` is not one of the 14 ISO 10962 category letters.
assert_eq!(
Cfi::parse("QSVUFR"),
Err(ValidationError::Structure {
rule: "CFI category must be one of E C D R O F S H I J K L T M",
}),
);Sourcepub fn validate(s: &str) -> Result<(), ValidationError>
pub fn validate(s: &str) -> Result<(), ValidationError>
Validates a CFI code without constructing one.
Equivalent to Cfi::parse(s).map(|_| ()); use it when only the
verdict is needed.
§Errors
Returns the same ValidationError variants as Cfi::parse.
§Examples
use regit_identifiers::Cfi;
assert!(Cfi::validate("ESVUFR").is_ok());
assert!(Cfi::validate("QSVUFR").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 Cfi without any validation.
The caller asserts that bytes holds the 6 ASCII characters of a
valid CFI. This exists for reconstructing a Cfi from bytes that were
validated earlier; prefer Cfi::parse for any untrusted input.
Bypassing validation has a consequence for Cfi::category_name: if
bytes[0] is not one of the 14 ISO 10962 category letters, the
accessor returns the empty string "" (the safe fallback).
§Examples
use regit_identifiers::Cfi;
let cfi = Cfi::from_bytes_unchecked(*b"ESVUFR");
assert_eq!(cfi.as_str(), "ESVUFR");Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the CFI code as a string slice.
§Examples
use regit_identifiers::Cfi;
assert_eq!(Cfi::parse("ESVUFR").unwrap().as_str(), "ESVUFR");Sourcepub fn as_bytes(&self) -> &[u8]
pub fn as_bytes(&self) -> &[u8]
Returns the CFI code as its 6 raw ASCII bytes.
§Examples
use regit_identifiers::Cfi;
assert_eq!(Cfi::parse("ESVUFR").unwrap().as_bytes(), b"ESVUFR");Sourcepub fn category(&self) -> char
pub fn category(&self) -> char
Returns the category letter, character 1.
This is always one of the 14 ISO 10962 category letters.
§Examples
use regit_identifiers::Cfi;
assert_eq!(Cfi::parse("ESVUFR").unwrap().category(), 'E');Sourcepub fn category_name(&self) -> &'static str
pub fn category_name(&self) -> &'static str
Returns the ISO 10962 name of the category, character 1.
The returned name is one of the 14 fixed category descriptions; it is
never empty for a value produced by Cfi::parse.
§Examples
use regit_identifiers::Cfi;
assert_eq!(Cfi::parse("ESVUFR").unwrap().category_name(), "Equities");
assert_eq!(Cfi::parse("DBFUGR").unwrap().category_name(), "Debt instruments");Sourcepub fn group(&self) -> char
pub fn group(&self) -> char
Returns the group letter, character 2.
The group narrows the category into a sub-class. Its meaning is
category-dependent and is not validated by Cfi::parse.
§Examples
use regit_identifiers::Cfi;
assert_eq!(Cfi::parse("ESVUFR").unwrap().group(), 'S');Sourcepub fn attributes(&self) -> &str
pub fn attributes(&self) -> &str
Returns the four attribute characters, characters 3–6.
The attributes further describe the instrument; an X in a position
means “not applicable”. Their meaning is category-dependent and is
not validated by Cfi::parse.
§Examples
use regit_identifiers::Cfi;
assert_eq!(Cfi::parse("ESVUFR").unwrap().attributes(), "VUFR");