macro_rules! mapping {
($($city_code:ident $country:ident => $city:expr, $time_zone:expr;)+) => {
#[derive(Debug, Clone, Copy)]
pub enum City {
$(
$city_code,
)+
}
impl City {
pub const fn all() -> &'static [Self] {
&[
$(
Self::$city_code,
)+
]
}
#[cfg(feature = "feat-iata-city-from-code")]
pub fn from_code(code: &str) -> Option<Self> {
use std::sync::OnceLock;
use std::collections::HashMap;
static MAPPING: OnceLock<HashMap<&'static str, City, foldhash::fast::RandomState>> = OnceLock::new();
MAPPING.get_or_init(|| {
City::all()
.iter()
.map(|city| (city.code(), *city))
.collect()
})
.get(code)
.copied()
}
pub const fn code(self) -> &'static str {
use City::*;
match self {
$(
$city_code => stringify!($city_code),
)+
}
}
#[cfg(feature = "feat-iata-city-time-zone")]
pub const fn time_zone(self) -> &'static str {
use City::*;
match self {
$(
$city_code => $time_zone,
)+
}
}
#[cfg(feature = "feat-iata-city-country")]
pub const fn country(self) -> &'static str {
use City::*;
match self {
$(
$city_code => stringify!($country),
)+
}
}
#[cfg(feature = "feat-iata-city-name")]
pub const fn name(self) -> Option<&'static str> {
use City::*;
match self {
$(
$city_code => $city,
)+
}
}
}
}
}