use iso_currency::Currency as IsoCurrency;
#[cfg(feature = "fundamentals")]
use paft::fundamentals::analysis::RecommendationGrade;
use paft::prelude::Currency;
fn main() {
println!("=== paft Extensible Enum Pattern Examples ===\n");
handle_currencies();
#[cfg(feature = "fundamentals")]
handle_recommendation_grades();
normalize_provider_data();
}
fn handle_currencies() {
println!("1. Handling Currencies:");
let input_codes = [
"USD",
"EUR",
"BTC",
"ETH",
"UNKNOWN_CURRENCY",
"xbt",
"bitcoin",
];
let currencies: Vec<Currency> = input_codes
.iter()
.map(|c| c.parse::<Currency>().unwrap())
.collect();
for currency in currencies {
if currency == Currency::Iso(IsoCurrency::USD) {
println!(" ✓ US Dollar - major reserve currency");
} else if currency == Currency::Iso(IsoCurrency::EUR) {
println!(" ✓ Euro - major reserve currency");
} else if currency == Currency::BTC || currency == Currency::ETH {
println!(" ✓ {currency} - known currency");
} else {
println!(
" ⚠ Unknown currency: {} - needs investigation",
currency.code()
);
}
}
println!();
}
#[cfg(feature = "fundamentals")]
fn handle_recommendation_grades() {
println!("2. Processing Recommendation Grades:");
let grades = vec![
RecommendationGrade::StrongBuy,
RecommendationGrade::Buy,
"MARKET_PERFORM".parse::<RecommendationGrade>().unwrap(),
RecommendationGrade::Outperform, ];
for grade in grades {
match grade {
RecommendationGrade::StrongBuy => println!(" ✓ Strong Buy - very bullish"),
RecommendationGrade::Buy => println!(" ✓ Buy - bullish"),
RecommendationGrade::Outperform => println!(" ✓ Outperform - bullish"),
RecommendationGrade::Hold => println!(" ✓ Hold - neutral"),
other => println!(" ⚠ Unknown grade: {other} - needs interpretation"),
}
}
println!();
}
fn normalize_provider_data() {
println!("3. Normalizing Provider-Specific Data:");
let generic_currencies = vec!["USD", "EUR", "BTC", "DOLLAR"];
let alpha_vantage_currencies = vec!["US_DOLLAR", "EURO", "BITCOIN", "UNKNOWN", "XBT"];
println!(" Generic provider currencies:");
for code in generic_currencies {
let currency = code.parse::<Currency>().unwrap();
println!(" {} -> {}", code, format_currency(¤cy));
}
println!(" Alpha Vantage currencies:");
for code in alpha_vantage_currencies {
let currency = code.parse::<Currency>().unwrap();
println!(" {} -> {}", code, format_currency(¤cy));
}
println!();
}
fn format_currency(currency: &Currency) -> String {
if currency == &Currency::Iso(IsoCurrency::USD) {
"USD (canonical)".to_string()
} else if currency == &Currency::Iso(IsoCurrency::EUR) {
"EUR (canonical)".to_string()
} else {
format!("{currency} (canonical)")
}
}