abbreviation_trait/
lib.rs

1pub trait Abbreviation {
2    fn abbreviation(&self) -> &'static str;
3}
4
5/// A trait for parsing an entity (typically) from a country code abbreviation.
6/// This can be ISO 3166 Alpha-2 (e.g. "US") or Alpha-3 (e.g. "USA"), or any
7/// other recognized short code as needed.
8pub trait TryFromAbbreviation: Sized {
9    /// The associated error type returned upon failure.
10    type Error;
11
12    /// Attempt to convert an abbreviation into `Self`.
13    fn try_from_abbreviation(abbr: &str) -> Result<Self, Self::Error>;
14}
15
16#[derive(Debug)]
17pub enum TryFromAbbreviationError {
18    /// The given abbreviation is not recognized in this region.
19    InvalidAbbreviation,
20}