ftracker_identifiers/lib.rs
1//! Validated, `no_std`-first identifier types.
2//!
3//! This crate provides small, `Copy`, allocation-free value types that can only ever hold a valid
4//! identifier. Every constructor runs full validation up front, so there is no partially validated
5//! state: if you hold one of these types, it is valid.
6//!
7//! # Identifiers
8//!
9//! * [`Cnpj`]: Brazil's Cadastro Nacional da Pessoa Jurídica, the national registry identifier for
10//! legal entities. It supports the punctuated `AA.AAA.AAA/AAAA-DD` form, the compact 14-character
11//! form, the legacy numeric layout, and the 2026 alphanumeric layout, validated with the Módulo
12//! 11 checksum.
13//! * [`Isin`]: the ISO 6166 International Securities Identification Number, a 12-character
14//! securities identifier validated with the ISO 6166 Luhn check digit.
15//! * [`Cfi`]: the ISO 10962 Classification of Financial Instruments code, a six letter taxonomy
16//! code validated against an embedded copy of the standard's code table.
17//! * [`CountryCode`]: the ISO 3166-1 alpha-2 country code, two letters validated against the
18//! officially assigned set.
19//!
20//! # Design
21//!
22//! * No invalid state is representable. Every constructor runs the full validation rules and
23//! returns a typed error on failure. There is no unchecked public constructor.
24//! * `no_std` first. The crate is `#![no_std]` by default and relies only on `core` and `alloc`.
25//! The `std` feature is additive.
26//! * Zero allocation and `Copy`. Each type wraps a fixed size byte array, and parsing, validation,
27//! and every accessor operate on the stack.
28//! * Consistent ordering and hashing. Ordering and hashing operate over the raw ASCII bytes and
29//! match [`str`] ordering on the string accessor, so every type works as a map or set key.
30//!
31//! # Feature flags
32//!
33//! The optional integrations are off by default and purely additive. Enabling one never changes the
34//! behavior of the parsers or the validation rules:
35//!
36//! * `std` (default): enables the standard library and the `std` support of any enabled optional
37//! dependency.
38//! * `serde`: (de)serializes each type as its canonical string. Deserialization re-runs full
39//! validation.
40//! * `schemars`: implements `JsonSchema` for each type. Implies `serde`.
41//! * `arbitrary`: implements `Arbitrary` for each type, generating valid values for fuzz targets.
42//! * `proptest`: exposes reusable `proptest` strategies for generating valid values.
43//!
44//! # Example
45//!
46//! ```
47//! use ftracker_identifiers::{Cnpj, Isin, Cfi, CountryCode};
48//!
49//! let cnpj = Cnpj::parse("00.000.000/0001-91").unwrap();
50//! assert_eq!(cnpj.as_str(), "00000000000191");
51//!
52//! let isin = Isin::parse("US0378331005").unwrap();
53//! assert_eq!(isin.country_code(), "US");
54//!
55//! let cfi = Cfi::parse("ESVUFR").unwrap();
56//! assert_eq!(cfi.category(), 'E');
57//!
58//! let country = CountryCode::parse("br").unwrap();
59//! assert_eq!(country.as_str(), "BR");
60//! ```
61#![cfg_attr(not(feature = "std"), no_std)]
62#![warn(missing_docs)]
63#![deny(rustdoc::broken_intra_doc_links)]
64extern crate alloc;
65
66pub mod cnpj;
67#[doc(inline)]
68pub use cnpj::{Cnpj, CnpjError, FormattedCnpj};
69
70pub mod isin;
71#[doc(inline)]
72pub use isin::{Isin, IsinError};
73
74pub mod cfi;
75#[doc(inline)]
76pub use cfi::{Cfi, CfiError};
77
78pub mod country;
79#[doc(inline)]
80pub use country::{CountryCode, CountryCodeError};