Skip to main content

SecurityId

Enum SecurityId 

Source
pub enum SecurityId {
    Isin(Isin),
    Cusip(Cusip),
    Sedol(Sedol),
    Lei(Lei),
    Figi(Figi),
    Bic(Bic),
    Mic(Mic),
    Cfi(Cfi),
    Wkn(Wkn),
    Valor(Valor),
}
Expand description

Any one validated securities identifier, tagged by its kind.

A SecurityId is the result of SecurityId::detect: a value that has already been parsed and fully validated as exactly one of the identifier types this crate supports. Each variant wraps the corresponding validated identifier, so unwrapping a SecurityId yields a value whose invariants are already proven. It is Copy and allocates nothing.

§Examples

use regit_identifiers::detect::SecurityId;

let id = SecurityId::detect("DEUTDEFF").unwrap();
match id {
    SecurityId::Bic(bic) => assert_eq!(bic.country_code(), "DE"),
    _ => panic!("DEUTDEFF is a BIC"),
}

Variants§

§

Isin(Isin)

A validated ISIN.

§

Cusip(Cusip)

A validated CUSIP / CINS number.

§

Sedol(Sedol)

A validated SEDOL.

§

Lei(Lei)

A validated LEI.

§

Figi(Figi)

A validated FIGI.

§

Bic(Bic)

A validated BIC.

§

Mic(Mic)

A validated MIC.

§

Cfi(Cfi)

A validated CFI code.

§

Wkn(Wkn)

A validated WKN.

§

Valor(Valor)

A validated VALOR.

Implementations§

Source§

impl SecurityId

Source

pub fn detect(s: &str) -> Option<Self>

Auto-detects which kind of identifier a raw string is.

Candidate kinds are tried in a fixed, checksum-strength-first order — LEI, ISIN, FIGI, CUSIP, SEDOL, BIC, then MIC — and the first whose strict parse accepts the input wins. Because each candidate is a full parse, a kind is reported only when the input is structurally valid for it and, where the standard defines one, carries a correct check digit.

The 12-character ISIN-versus-FIGI ambiguity is resolved by trying ISIN first; a genuine FIGI is never a valid ISIN (it requires character 3 to be G and forbids the ISIN-colliding provider prefixes) and so falls through to the FIGI branch.

MIC is detected only when the mic-registry feature is enabled and the string is a registered MIC — a structurally valid but unregistered code such as ZZZZ is never reported.

The structural-only kinds CFI, WKN, and VALOR are not auto-detected: they carry no check digit and overlap too heavily to distinguish. detect returns None when no checksum-bearing kind (or registered MIC) fits — parse those kinds explicitly instead.

§Examples
use regit_identifiers::detect::{IdentifierKind, SecurityId};

// Each kind is recognised from a real identifier.
assert_eq!(
    SecurityId::detect("5493001KJTIIGC8Y1R12").unwrap().kind(),
    IdentifierKind::Lei,
);
assert_eq!(
    SecurityId::detect("BBG000BLNNH6").unwrap().kind(),
    IdentifierKind::Figi,
);

// Garbage, and the structural-only kinds, return `None`.
assert!(SecurityId::detect("not-an-identifier").is_none());
Source

pub fn kind(&self) -> IdentifierKind

Returns the IdentifierKind tag of this identifier.

§Examples
use regit_identifiers::detect::{IdentifierKind, SecurityId};

let id = SecurityId::detect("037833100").unwrap();
assert_eq!(id.kind(), IdentifierKind::Cusip);
Source

pub fn as_str(&self) -> &str

Returns the wrapped identifier as a string slice.

The returned &str is the canonical text of the underlying validated identifier, exactly as its own as_str would render it.

§Examples
use regit_identifiers::detect::SecurityId;

let id = SecurityId::detect("US0378331005").unwrap();
assert_eq!(id.as_str(), "US0378331005");

Trait Implementations§

Source§

impl Clone for SecurityId

Source§

fn clone(&self) -> SecurityId

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 Debug for SecurityId

Source§

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

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

impl PartialEq for SecurityId

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for SecurityId

Source§

impl Eq for SecurityId

Source§

impl StructuralPartialEq for SecurityId

Auto Trait Implementations§

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.