ftracker-identifiers
Validated, no_std-first identifier types for Rust. It is:
-
Correct: parsing runs full validation up front, so an invalid identifier can never be represented. Once you hold one of these types, there is no partially validated state to guard against.
-
no_stdfirst: the crate builds oncoreandalloconly. Thestdfeature is additive, not required. -
Zero-cost: every type is
Copy, wraps a fixed-size byte array, and performs parsing, validation, and every accessor on the stack.
API Docs | Guide | Contributing
Overview
This crate provides small, allocation-free value types that can only ever hold a valid identifier. It currently ships four:
Cnpj: Brazil's Cadastro Nacional da Pessoa Jurídica, the national registry identifier for legal entities. Supports the punctuatedAA.AAA.AAA/AAAA-DDform, the compact 14-character form, the legacy numeric layout, and the 2026 alphanumeric layout, all 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.
Example
Add the crate to your Cargo.toml:
[]
= "0.0.1"
Then parse and inspect identifiers:
use ;
// CNPJ accepts punctuated or compact input and exposes structured accessors.
let cnpj = parse.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
// ISIN exposes its country code as a validated `CountryCode`.
let isin = parse.unwrap;
assert_eq!;
assert_eq!;
// CFI decomposes into its ISO 10962 category and group letters.
let cfi = parse.unwrap;
assert_eq!;
assert_eq!;
// Country codes are case-folded to their canonical uppercase form.
let country = parse.unwrap;
assert_eq!;
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_stdfirst. The crate is#![no_std]by default and relies only oncoreandalloc. Thestdfeature is additive.- Zero allocation and
Copy. Each type wraps a fixed-size byte array. Parsing, validation, and every accessor operate on the stack. - Consistent ordering and hashing. Ordering and hashing operate over the raw
ASCII bytes and match
strordering on the string accessor, so every type works as a map or set key.
Feature flags
std(default): enables the standard library and thestdsupport of any enabled optional dependency.serde: (de)serializes each type as its canonical string. Deserialization re-runs full validation.schemars: implementsJsonSchemafor each type. Impliesserde.arbitrary: implementsArbitraryfor each type, generating valid values for fuzz targets.proptest: exposes reusablepropteststrategies for generating valid values.
Supported Rust Versions
The minimum supported Rust version is 1.93.0. Raising the MSRV is treated as a breaking change and only happens in a version bump.
Contributing
Contributions are welcome. See the contributing guide to get started, and please note that this project follows a Code of Conduct.
License
This project is licensed under the MIT license.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you shall be licensed as MIT, without any additional terms or conditions.