mod display;
mod from_str;
mod try_from;
use std::{collections::HashMap, sync::OnceLock};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use strum::{EnumCount, EnumIter, IntoEnumIterator, IntoStaticStr};
use unicase::UniCase;
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize), serde(rename_all = "UPPERCASE"))]
#[derive(
Copy,
Clone,
Debug,
Default,
EnumCount,
EnumIter,
Eq,
Hash,
IntoStaticStr,
Ord,
PartialEq,
PartialOrd,
)]
#[strum(serialize_all = "UPPERCASE")]
pub enum Currency
{
Aud,
Bgn,
Brl,
Cad,
Chf,
Cny,
Czk,
Dkk,
#[default]
Eur,
Gbp,
Hkd,
Huf,
Idr,
Ils,
Inr,
Isk,
Jpy,
Krw,
Mxn,
Myr,
Nok,
Nzd,
Php,
Pln,
Ron,
Rub,
Sek,
Sgd,
Thb,
Try,
Usd,
Zar,
}
impl Currency
{
pub(crate) fn reverse_lookup(s: &str) -> Option<Self>
{
static CELL: OnceLock<HashMap<UniCase<&'static str>, Currency>> = OnceLock::new();
CELL.get_or_init(|| {
Self::iter().map(|currency| (UniCase::new(currency.into()), currency)).collect()
})
.get(&s.into())
.copied()
}
}