use std::fmt::Display;
#[derive(Debug)]
pub enum CashAction {
DepositWithdraw,
BrokerIntPaid,
BrokerIntRcvd,
WhTax,
BondIntRcvd,
BondIntPaid,
Fees,
Dividend,
PaymentInLieu,
CommAdj
}
impl Display for CashAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
pub fn cash_action(action: &str) -> String {
match action {
"Deposits/Withdrawals" => CashAction::DepositWithdraw.to_string(),
"Broker Interest Paid" => CashAction::BrokerIntPaid.to_string(),
"Broker Interest Received" => CashAction::BrokerIntRcvd.to_string(),
"Withholding Tax" => CashAction::WhTax.to_string(),
"Bond Interest Received" => CashAction::BondIntRcvd.to_string(),
"Bond Interest Paid" => CashAction::BondIntPaid.to_string(),
"Other Fees" => CashAction::Fees.to_string(),
"Dividends" => CashAction::Dividend.to_string(),
"Payment In Lieu Of Dividends" => CashAction::PaymentInLieu.to_string(),
"Commission Adjustments" => CashAction::CommAdj.to_string(),
_ => panic!("Unrecognized cash action type: {}", action)
}
}
#[cfg(test)]
mod tests {
use super::cash_action;
#[test]
fn test_mapping() {
let ib_type = "Withholding Tax";
let actual = cash_action(ib_type);
assert_eq!("WhTax", actual);
}
}