#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![no_std]
#[cfg(feature = "short-names")]
use core::fmt;
mod countries;
#[cfg(feature = "short-names")]
mod countries_short_names;
pub use countries::{CountryAlpha2, CountryAlpha3};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Country {
alpha2: CountryAlpha2,
alpha3: CountryAlpha3,
numeric: u16,
}
impl Country {
#[inline]
const fn new(
alpha2: CountryAlpha2,
alpha3: CountryAlpha3,
numeric: u16,
) -> Self {
Self {
alpha2,
alpha3,
numeric,
}
}
#[inline]
pub const fn alpha2(&self) -> CountryAlpha2 {
self.alpha2
}
#[inline]
pub const fn alpha3(&self) -> CountryAlpha3 {
self.alpha3
}
#[inline]
pub const fn numeric(&self) -> u16 {
self.numeric
}
#[cfg(feature = "short-names")]
#[inline]
pub const fn short_name(&self) -> &'static str {
countries_short_names::short_name_from_alpha2(self.alpha2)
}
}
#[cfg(feature = "short-names")]
impl fmt::Display for Country {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.short_name().fmt(f)
}
}