1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
use std::fmt::{Display, Formatter};
use inquire::{error::InquireResult, Select};
fn main() -> InquireResult<()> {
let ans: Currency = Select::new("Currency:", Currency::VARIANTS.to_vec()).prompt()?;
match ans {
Currency::BRL | Currency::USD | Currency::CAD | Currency::EUR | Currency::GBP => {
bank_transfer();
}
Currency::BTC | Currency::LTC => crypto_transfer(),
}
Ok(())
}
fn bank_transfer() {
// ask for bank account
// transfer funds
}
fn crypto_transfer() {
// ask for wallet address
// transfer funds
}
#[derive(Debug, Copy, Clone)]
#[allow(clippy::upper_case_acronyms)]
enum Currency {
BRL,
USD,
CAD,
EUR,
GBP,
BTC,
LTC,
}
impl Currency {
// could be generated by macro
const VARIANTS: &'static [Currency] = &[
Self::BRL,
Self::USD,
Self::CAD,
Self::EUR,
Self::GBP,
Self::BTC,
Self::LTC,
];
}
impl Display for Currency {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(f, "{self:?}")
}
}
|