pub struct CountryCode { /* private fields */ }Expand description
A CAPCO country / country-group code, 2–16 ASCII bytes.
Covers every entry in the CVE country code list:
- 1× 2-char (
EU) - 280× 3-char trigraphs (
USA,GBR,AUS, …) - 58× 4-char tetragraphs / country-group codes (
FVEY,ACGU,NATO,RSMA, …) - 1× 15-char (
AUSTRALIA_GROUP)
The inner bytes are private; construction goes through
CountryCode::try_new which enforces the CAPCO byte-set invariant
(ASCII uppercase letters, ASCII digits, underscore — covers AX2,
AX3, AUSTRALIA_GROUP, and the standard alpha trigraphs/
tetragraphs) so that CountryCode::as_str can return a &str
infallibly without panicking at runtime.
Copy is preserved so the type composes in iterator chains and
BTreeSet-based intersection without manual .clone() calls.
The fixed-array form keeps each CountryCode entry inline in
IsmAttributes::rel_to (Box<[CountryCode]>) on the parsing
hot path — no per-code heap allocation.
Implementations§
Source§impl CountryCode
impl CountryCode
Sourcepub const USA: CountryCode
pub const USA: CountryCode
The always-valid USA country code constant.
Constructed via CountryCode::try_new in const context;
the expect is statically unreachable for b"USA" (3 bytes,
all ASCII uppercase) and exists only to satisfy const
unwrap.
Sourcepub const fn try_new(bytes: &[u8]) -> Option<CountryCode>
pub const fn try_new(bytes: &[u8]) -> Option<CountryCode>
Attempt to construct a country code from a byte slice.
Returns None if bytes:
- is shorter than 2 bytes (
EUis the shortest CVE entry) or longer than [COUNTRY_CODE_CAPACITY] bytes - contains any byte outside the CAPCO country-code byte set (ASCII uppercase letter, ASCII digit, underscore)
Membership in the CVE recognition set is a separate check —
see [crate::CapcoTokenSet::is_trigraph] (the trait method
covers any known country code, not only 3-char trigraphs).
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Return the country code as a string slice.
Infallible because construction via CountryCode::try_new
(or CountryCode::USA) guarantees every active byte is in the
CAPCO byte set, which is a subset of ASCII / valid UTF-8.
Trait Implementations§
Source§impl Clone for CountryCode
impl Clone for CountryCode
Source§fn clone(&self) -> CountryCode
fn clone(&self) -> CountryCode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more