currencies in client never drifts from the server from now on
This commit is contained in:
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user