Skip to main content

Cfi

Struct Cfi 

Source
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

ConstructorAccepts
Cfi::parse / Cfi::new6-character strings, any ASCII case, trimmed
Cfi::from_bytesExactly 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

Source

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

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

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

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

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

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

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

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

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl AsRef<[u8]> for Cfi

Source§

fn as_ref(&self) -> &[u8]

Equivalent to Cfi::as_bytes, borrowed as a slice.

Source§

impl AsRef<str> for Cfi

Source§

fn as_ref(&self) -> &str

Equivalent to Cfi::as_str.

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<'de> Deserialize<'de> for Cfi

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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§

fn from_str(s: &str) -> Result<Self, Self::Err>

Delegates to Cfi::parse, enabling input.parse::<Cfi>() and use in generic code bounded by FromStr.

Source§

type Err = CfiError

The associated error which can be returned from parsing.
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 JsonSchema for Cfi

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn json_schema(_: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

impl Ord for Cfi

Source§

fn cmp(&self, other: &Cfi) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. 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 PartialEq<&str> for Cfi

Source§

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

Compares against a string slice by its canonical 6 character representation.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Cfi> for str

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 PartialEq<Cfi> for &str

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 PartialEq<str> for Cfi

Source§

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

Compares against a string slice by its canonical 6 character representation.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Cfi

Source§

fn partial_cmp(&self, other: &Cfi) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Cfi

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Cfi

Source§

impl TryFrom<&[u8]> for Cfi

Source§

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.

Source§

type Error = CfiError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&str> for Cfi

Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Delegates to Cfi::parse, enabling Cfi::try_from(input) and use in generic code bounded by TryFrom<&str>.

Source§

type Error = CfiError

The type returned in the event of a conversion error.
Source§

impl TryFrom<[u8; 6]> for Cfi

Source§

fn try_from(value: [u8; 6]) -> Result<Self, Self::Error>

Delegates to Cfi::from_bytes. The bytes must already be pre normalized uppercase ASCII letters.

Source§

type Error = CfiError

The type returned in the event of a conversion error.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V