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
impl SecurityId
Sourcepub fn detect(s: &str) -> Option<Self>
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());Sourcepub fn kind(&self) -> IdentifierKind
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);Sourcepub fn as_str(&self) -> &str
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
impl Clone for SecurityId
Source§fn clone(&self) -> SecurityId
fn clone(&self) -> SecurityId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more