Skip to main content

Crate ftracker_identifiers

Crate ftracker_identifiers 

Source
Expand description

Validated, no_std-first identifier types.

This crate provides small, Copy, allocation-free value types that can only ever hold a valid identifier. Every constructor runs full validation up front, so there is no partially validated state: if you hold one of these types, it is valid.

§Identifiers

  • Cnpj: Brazil’s Cadastro Nacional da Pessoa Jurídica, the national registry identifier for legal entities. It supports the punctuated AA.AAA.AAA/AAAA-DD form, the compact 14-character form, the legacy numeric layout, and the 2026 alphanumeric layout, validated with the Módulo 11 checksum.
  • Isin: the ISO 6166 International Securities Identification Number, a 12-character securities identifier validated with the ISO 6166 Luhn check digit.
  • Cfi: the ISO 10962 Classification of Financial Instruments code, a six letter taxonomy code validated against an embedded copy of the standard’s code table.
  • CountryCode: the ISO 3166-1 alpha-2 country code, two letters validated against the officially assigned set.

§Design

  • No invalid state is representable. Every constructor runs the full validation rules and returns a typed error on failure. There is no unchecked public constructor.
  • no_std first. The crate is #![no_std] by default and relies only on core and alloc. The std feature is additive.
  • Zero allocation and Copy. Each type wraps a fixed size byte array, and parsing, validation, and every accessor operate on the stack.
  • Consistent ordering and hashing. Ordering and hashing operate over the raw ASCII bytes and match str ordering on the string accessor, so every type works as a map or set key.

§Feature flags

The optional integrations are off by default and purely additive. Enabling one never changes the behavior of the parsers or the validation rules:

  • std (default): enables the standard library and the std support of any enabled optional dependency.
  • serde: (de)serializes each type as its canonical string. Deserialization re-runs full validation.
  • schemars: implements JsonSchema for each type. Implies serde.
  • arbitrary: implements Arbitrary for each type, generating valid values for fuzz targets.
  • proptest: exposes reusable proptest strategies for generating valid values.

§Example

use ftracker_identifiers::{Cnpj, Isin, Cfi, CountryCode};

let cnpj = Cnpj::parse("00.000.000/0001-91").unwrap();
assert_eq!(cnpj.as_str(), "00000000000191");

let isin = Isin::parse("US0378331005").unwrap();
assert_eq!(isin.country_code(), "US");

let cfi = Cfi::parse("ESVUFR").unwrap();
assert_eq!(cfi.category(), 'E');

let country = CountryCode::parse("br").unwrap();
assert_eq!(country.as_str(), "BR");

Modules§

cfi
CFI (Classification of Financial Instruments) — the ISO 10962 six-letter code that classifies a financial instrument by category, group, and four attributes.
cnpj
CNPJ (Cadastro Nacional da Pessoa Jurídica) — Brazil’s national registry identifier for legal entities, issued by the Receita Federal.
country
ISO 3166-1 alpha-2 country codes: the two letter codes that identify countries, dependent territories, and special areas of geographical interest.
isin
ISIN (International Securities Identification Number) — the ISO 6166 identifier for a fungible financial security.

Structs§

Cfi
A validated CFI (Classification of Financial Instruments, ISO 10962).
Cnpj
A validated CNPJ (Cadastro Nacional da Pessoa Jurídica).
CountryCode
A validated ISO 3166-1 alpha-2 country code.
FormattedCnpj
A stack-allocated, punctuated rendering of a Cnpj (AA.AAA.AAA/AAAA-DD), e.g. "12.ABC.345/01DE-35".
Isin
A validated ISIN (International Securities Identification Number, ISO 6166).

Enums§

CfiError
The set of reasons a CFI string can fail validation.
CnpjError
The error returned when a Cnpj fails to parse or validate.
CountryCodeError
The set of reasons a country code string can fail validation.
IsinError
The set of reasons an ISIN string can fail validation.