1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! 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");
//! ```
extern crate alloc;
pub use ;
pub use ;
pub use ;
pub use ;