currencies in client never drifts from the server from now on

This commit is contained in:
Priec
2026-09-02 17:12:26 +02:00
parent 4ba518ab4e
commit 94ea9d1f7f
6 changed files with 28 additions and 2 deletions

View File

@@ -18,6 +18,24 @@ pub fn require_iso_currency_code(currency_code: &str) -> Result<&'static iso::Cu
iso::find(currency_code).ok_or_else(|| format!("Unknown ISO-4217 currency: {currency_code}"))
}
/// Returns every currency accepted by [`require_iso_currency_code`], ordered by
/// its canonical alphabetic code.
pub fn iso_currency_codes() -> Vec<&'static str> {
let mut currencies = Vec::new();
for first in b'A'..=b'Z' {
for second in b'A'..=b'Z' {
for third in b'A'..=b'Z' {
let bytes = [first, second, third];
let code = std::str::from_utf8(&bytes).expect("uppercase ASCII currency code");
if let Some(currency) = iso::find(code) {
currencies.push(currency.iso_alpha_code);
}
}
}
}
currencies
}
#[cfg(test)]
mod tests {
use super::*;