pub struct Cfi { /* private fields */ }Expand description
A validated CFI (Classification of Financial Instruments, ISO 10962).
Cfi is a 6-byte, Copy, allocation-free value object. Once constructed, it is guaranteed to
describe a category, group, and four attribute codes defined by ISO 10962 — there is no way to
get a Cfi that hasn’t passed validation.
Internally, the identifier is stored as raw uppercase ASCII letters ('A'...='Z').
§Constructing a Cfi
| Constructor | Accepts |
|---|---|
Cfi::parse / Cfi::new | 6-character strings, any ASCII case, trimmed |
Cfi::from_bytes | Exactly 6 pre-normalized uppercase ASCII bytes |
FromStr / TryFrom<&str> | Same as parse, for use in generic code |
All of them run the same validation and return CfiError on failure.
See the module-level documentation for the segment layout and design rationale.
Implementations§
Source§impl Cfi
impl Cfi
Sourcepub fn parse(input: &str) -> Result<Self, CfiError>
pub fn parse(input: &str) -> Result<Self, CfiError>
Parses a CFI from a string.
The parser trims surrounding whitespace and folds ASCII letters to uppercase before
validation. This is the primary constructor; Cfi::new, FromStr, and
TryFrom<&str> all delegate to it.
§Errors
Returns CfiError if the input is empty, does not contain exactly 6 characters after
trimming, contains a non-letter character, or names a category, group, or attribute code
that ISO 10962 does not define.
§Examples
use ftracker_identifiers::Cfi;
assert!(Cfi::parse("ESVUFR").is_ok());
assert!(Cfi::parse("esvufr").is_ok()); // lowercase is folded automatically
assert!(Cfi::parse(" ESVUFR ").is_ok()); // surrounding whitespace is trimmed
assert!(Cfi::parse("EZVUFR").is_err()); // 'Z' is not a group of category 'E'Sourcepub fn new(input: &str) -> Result<Self, CfiError>
pub fn new(input: &str) -> Result<Self, CfiError>
Alias for Cfi::parse.
§Errors
See Cfi::parse.
§Examples
use ftracker_identifiers::Cfi;
assert_eq!(Cfi::new("ESVUFR"), Cfi::parse("ESVUFR"));Sourcepub fn from_bytes(bytes: [u8; 6]) -> Result<Self, CfiError>
pub fn from_bytes(bytes: [u8; 6]) -> Result<Self, CfiError>
Constructs a Cfi directly from 6 raw ASCII bytes.
Each byte must already be an uppercase letter valid for its position. Use Cfi::parse if
the input might contain surrounding whitespace or lowercase letters.
§Errors
Returns CfiError under the same conditions as Cfi::parse, except that length is
guaranteed by the [u8; 6] type itself: CfiError::InvalidLength cannot occur here.
§Examples
use ftracker_identifiers::Cfi;
let cfi = Cfi::from_bytes(*b"ESVUFR").unwrap();
assert_eq!(cfi.as_str(), "ESVUFR");
// An undefined attribute code is rejected just like it would be through `parse`.
assert!(Cfi::from_bytes(*b"ESZUFR").is_err());Sourcepub fn as_bytes(&self) -> &[u8; 6]
pub fn as_bytes(&self) -> &[u8; 6]
Returns the 6 raw ASCII bytes backing this CFI (for example, b"ESVUFR").
§Examples
use ftracker_identifiers::Cfi;
let cfi = Cfi::parse("ESVUFR").unwrap();
assert_eq!(cfi.as_bytes(), b"ESVUFR");Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the full 6-character CFI as a &str.
This never allocates: the bytes are guaranteed to be valid ASCII by construction.
§Examples
use ftracker_identifiers::Cfi;
let cfi = Cfi::parse("ESVUFR").unwrap();
assert_eq!(cfi.as_str(), "ESVUFR");Sourcepub fn category(&self) -> char
pub fn category(&self) -> char
Returns the category code (position 1).
§Examples
use ftracker_identifiers::Cfi;
let cfi = Cfi::parse("ESVUFR").unwrap();
assert_eq!(cfi.category(), 'E');Sourcepub fn group(&self) -> char
pub fn group(&self) -> char
Returns the group code (position 2).
§Examples
use ftracker_identifiers::Cfi;
let cfi = Cfi::parse("ESVUFR").unwrap();
assert_eq!(cfi.group(), 'S');Sourcepub fn attributes(&self) -> [char; 4]
pub fn attributes(&self) -> [char; 4]
Returns the four attribute codes (positions 3–6), in order.
§Examples
use ftracker_identifiers::Cfi;
let cfi = Cfi::parse("ESVUFR").unwrap();
assert_eq!(cfi.attributes(), ['V', 'U', 'F', 'R']);Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Cfi
impl<'a> Arbitrary<'a> for Cfi
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreimpl Copy for Cfi
Source§impl<'de> Deserialize<'de> for Cfi
impl<'de> Deserialize<'de> for Cfi
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for Cfi
Source§impl JsonSchema for Cfi
impl JsonSchema for Cfi
Source§fn json_schema(_: &mut SchemaGenerator) -> Schema
fn json_schema(_: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for Cfi
impl Ord for Cfi
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Cfi
impl PartialOrd for Cfi
impl StructuralPartialEq for Cfi
Source§impl TryFrom<&[u8]> for Cfi
impl TryFrom<&[u8]> for Cfi
Source§fn try_from(value: &[u8]) -> Result<Self, Self::Error>
fn try_from(value: &[u8]) -> Result<Self, Self::Error>
Validates a byte slice as a CFI. The slice must be exactly 6 pre normalized uppercase ASCII
bytes; any other length yields CfiError::InvalidLength. Once the length is confirmed,
this behaves like Cfi::from_bytes.