Skip to main content

Cfi

Struct Cfi 

Source
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

Source

pub const LENGTH: usize = 6

The number of characters in a CFI code.

Source

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
§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",
    }),
);
Source

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());
Source

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");
Source

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");
Source

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");
Source

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');
Source

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");
Source

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');
Source

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");

Trait Implementations§

Source§

impl AsRef<str> for Cfi

Source§

fn as_ref(&self) -> &str

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

impl Clone for Cfi

Source§

fn clone(&self) -> Cfi

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 Cfi

Source§

impl Debug for Cfi

Source§

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

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

impl Display for Cfi

Source§

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

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

impl Eq for Cfi

Source§

impl FromStr for Cfi

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 Cfi

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 Cfi

Source§

fn eq(&self, other: &Cfi) -> 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 Cfi

Auto Trait Implementations§

§

impl Freeze for Cfi

§

impl RefUnwindSafe for Cfi

§

impl Send for Cfi

§

impl Sync for Cfi

§

impl Unpin for Cfi

§

impl UnsafeUnpin for Cfi

§

impl UnwindSafe for Cfi

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.