Changed Box<Erro> to Box<dyn Error>. Resolves #29.

This commit is contained in:
scoobybejesus 2019-08-30 18:25:14 -04:00
parent f1e9a7f418
commit 5c61353cf0
10 changed files with 32 additions and 30 deletions

2
Cargo.lock generated
View File

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.6" version = "0.7.6"

View File

@ -179,7 +179,7 @@ impl Movement {
raw_accts: &HashMap<u16, RawAccount>, raw_accts: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
)-> Result<d128, Box<Error>> { )-> Result<d128, Box<dyn Error>> {
let txn = txns_map.get(&self.transaction_key).expect("Couldn't get txn. Tx num invalid?"); let txn = txns_map.get(&self.transaction_key).expect("Couldn't get txn. Tx num invalid?");
match txn.transaction_type(ar_map, raw_accts, acct_map)? { match txn.transaction_type(ar_map, raw_accts, acct_map)? {
@ -201,7 +201,7 @@ impl Movement {
raw_accts: &HashMap<u16, RawAccount>, raw_accts: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
)-> Result<d128, Box<Error>> { )-> Result<d128, Box<dyn Error>> {
let txn = txns_map.get(&self.transaction_key).expect("Couldn't get txn. Tx num invalid?"); let txn = txns_map.get(&self.transaction_key).expect("Couldn't get txn. Tx num invalid?");
match txn.transaction_type(ar_map, raw_accts, acct_map)? { match txn.transaction_type(ar_map, raw_accts, acct_map)? {

View File

@ -18,7 +18,7 @@ use crate::core_functions::InventoryCostingMethod;
use crate::string_utils; use crate::string_utils;
pub fn choose_file_for_import() -> Result<PathBuf, Box<Error>> { pub fn choose_file_for_import() -> Result<PathBuf, Box<dyn Error>> {
println!("Please input a file (absolute or relative path) to import: "); println!("Please input a file (absolute or relative path) to import: ");
@ -26,7 +26,7 @@ pub fn choose_file_for_import() -> Result<PathBuf, Box<Error>> {
Ok( PathBuf::from(file_str.unwrap()) ) Ok( PathBuf::from(file_str.unwrap()) )
} }
pub fn choose_export_dir() -> Result<PathBuf, Box<Error>> { pub fn choose_export_dir() -> Result<PathBuf, Box<dyn Error>> {
println!("Please input a file path for exports: "); println!("Please input a file path for exports: ");
@ -34,7 +34,7 @@ pub fn choose_export_dir() -> Result<PathBuf, Box<Error>> {
Ok( PathBuf::from(file_str.unwrap()) ) Ok( PathBuf::from(file_str.unwrap()) )
} }
fn _get_path() -> Result<(String), Box<Error>> { fn _get_path() -> Result<(String), Box<dyn Error>> {
struct MyHelper { struct MyHelper {
completer: FilenameCompleter, completer: FilenameCompleter,
@ -108,7 +108,7 @@ fn _get_path() -> Result<(String), Box<Error>> {
// } // }
// } // }
pub fn choose_inventory_costing_method() -> Result<InventoryCostingMethod, Box<Error>> { pub fn choose_inventory_costing_method() -> Result<InventoryCostingMethod, Box<dyn Error>> {
println!("Choose the lot inventory costing method. [Default: 1]"); println!("Choose the lot inventory costing method. [Default: 1]");
println!("1. LIFO according to the order the lot was created."); println!("1. LIFO according to the order the lot was created.");
@ -118,7 +118,7 @@ pub fn choose_inventory_costing_method() -> Result<InventoryCostingMethod, Box<E
let method = _costing_method()?; let method = _costing_method()?;
fn _costing_method() -> Result<InventoryCostingMethod, Box<Error>> { fn _costing_method() -> Result<InventoryCostingMethod, Box<dyn Error>> {
let mut input = String::new(); let mut input = String::new();
let stdin = io::stdin(); let stdin = io::stdin();
@ -149,7 +149,7 @@ pub fn inv_costing_from_cmd_arg(arg: String) -> Result<InventoryCostingMethod, &
} }
} }
pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bool, String), Box<Error>> { pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bool, String), Box<dyn Error>> {
let election: bool; let election: bool;
let date: String; let date: String;
@ -164,7 +164,7 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
let (election, date) = _elect_like_kind_arg(&cutoff_date_arg, provided_date)?; let (election, date) = _elect_like_kind_arg(&cutoff_date_arg, provided_date)?;
fn _elect_like_kind_arg(cutoff_date_arg: &Option<String>, provided_date: NaiveDate) -> Result<(bool, String), Box<Error>> { fn _elect_like_kind_arg(cutoff_date_arg: &Option<String>, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> {
let mut input = String::new(); let mut input = String::new();
let stdin = io::stdin(); let stdin = io::stdin();
@ -210,7 +210,7 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
let (election, date) = _no_elect_like_kind_arg()?; let (election, date) = _no_elect_like_kind_arg()?;
fn _no_elect_like_kind_arg() -> Result<(bool, String), Box<Error>> { fn _no_elect_like_kind_arg() -> Result<(bool, String), Box<dyn Error>> {
let mut input = String::new(); let mut input = String::new();
let stdin = io::stdin(); let stdin = io::stdin();

View File

@ -50,7 +50,7 @@ pub fn import_and_process_final(
HashMap<u32, ActionRecord>, HashMap<u32, ActionRecord>,
HashMap<u32, Transaction>, HashMap<u32, Transaction>,
Option<LikeKindSettings> Option<LikeKindSettings>
), Box<Error>> { ), Box<dyn Error>> {
let mut transactions_map: HashMap<u32, Transaction> = HashMap::new(); let mut transactions_map: HashMap<u32, Transaction> = HashMap::new();
let mut action_records_map: HashMap<u32, ActionRecord> = HashMap::new(); let mut action_records_map: HashMap<u32, ActionRecord> = HashMap::new();
@ -80,7 +80,7 @@ pub fn import_and_process_final(
action_records: &mut HashMap<u32, ActionRecord>, action_records: &mut HashMap<u32, ActionRecord>,
raw_acct_map: &mut HashMap<u16, RawAccount>, raw_acct_map: &mut HashMap<u16, RawAccount>,
acct_map: &mut HashMap<u16, Account>, acct_map: &mut HashMap<u16, Account>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let file = File::open(import_file_path)?; println!("CSV ledger file opened successfully.\n"); let file = File::open(import_file_path)?; println!("CSV ledger file opened successfully.\n");

View File

@ -22,7 +22,7 @@ pub fn create_lots_and_movements(
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
lot_map: &HashMap<(RawAccount, u32), Lot>, lot_map: &HashMap<(RawAccount, u32), Lot>,
) -> Result<HashMap<u32,Transaction>, Box<Error>> { ) -> Result<HashMap<u32,Transaction>, Box<dyn Error>> {
// Set values to be referred to repeatedly, potentially, in Incoming Exchange transactions // Set values to be referred to repeatedly, potentially, in Incoming Exchange transactions
let multiple_incoming_mvmts_per_ar = match &likekind_settings { let multiple_incoming_mvmts_per_ar = match &likekind_settings {
@ -579,7 +579,7 @@ fn get_base_and_quote_acct_for_dual_actionrecord_flow_tx(
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Result<(u16, u16), Box<Error>> { ) -> Result<(u16, u16), Box<dyn Error>> {
let txn = txns_map.get(&txn_num).expect("Couldn't get txn. Tx num invalid?"); let txn = txns_map.get(&txn_num).expect("Couldn't get txn. Tx num invalid?");
let og_flow_ar = ar_map.get(txn.action_record_idx_vec.first().unwrap()).unwrap(); let og_flow_ar = ar_map.get(txn.action_record_idx_vec.first().unwrap()).unwrap();

View File

@ -202,7 +202,7 @@ pub fn _5_transaction_mvmt_summaries_to_csv(
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let mut rows: Vec<Vec<String>> = [].to_vec(); let mut rows: Vec<Vec<String>> = [].to_vec();
let mut header: Vec<String> = [].to_vec(); let mut header: Vec<String> = [].to_vec();

View File

@ -19,7 +19,7 @@ pub fn import_accounts(
rdr: &mut csv::Reader<File>, rdr: &mut csv::Reader<File>,
raw_acct_map: &mut HashMap<u16, RawAccount>, raw_acct_map: &mut HashMap<u16, RawAccount>,
acct_map: &mut HashMap<u16, Account>, acct_map: &mut HashMap<u16, Account>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let header1: csv::StringRecord; let header1: csv::StringRecord;
header1 = rdr.headers()?.clone(); // account_num header1 = rdr.headers()?.clone(); // account_num
@ -119,7 +119,7 @@ pub fn import_transactions(
action_records: &mut HashMap<u32, ActionRecord>, action_records: &mut HashMap<u32, ActionRecord>,
raw_acct_map: &mut HashMap<u16, RawAccount>, raw_acct_map: &mut HashMap<u16, RawAccount>,
acct_map: &mut HashMap<u16, Account>, acct_map: &mut HashMap<u16, Account>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let mut this_tx_number = 0; let mut this_tx_number = 0;
let mut this_ar_number = 0; let mut this_ar_number = 0;

View File

@ -18,7 +18,7 @@ pub fn add_cost_basis_to_movements(
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let length = txns_map.len(); let length = txns_map.len();
@ -152,7 +152,7 @@ pub fn add_proceeds_to_movements(
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let length = txns_map.len(); let length = txns_map.len();
@ -209,7 +209,7 @@ pub fn apply_like_kind_treatment(
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let length = txns_map.len(); let length = txns_map.len();
for txn_num in 1..=length { for txn_num in 1..=length {
@ -234,7 +234,7 @@ fn update_current_txn_for_prior_likekind_treatment(
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let mut sum_of_outgoing_cost_basis_in_ar = d128!(0); let mut sum_of_outgoing_cost_basis_in_ar = d128!(0);
let txn = txns_map.get(&txn_num).unwrap(); let txn = txns_map.get(&txn_num).unwrap();
@ -300,7 +300,7 @@ fn perform_likekind_treatment_on_txn(
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<dyn Error>> {
let txn = txns_map.get(&txn_num).unwrap(); let txn = txns_map.get(&txn_num).unwrap();
let tx_type = txn.transaction_type(ars, raw_acct_map, acct_map)?; let tx_type = txn.transaction_type(ars, raw_acct_map, acct_map)?;

View File

@ -70,7 +70,7 @@ struct Cli {
} }
fn main() -> Result<(), Box<Error>> { fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args(); let args = Cli::from_args();
@ -107,13 +107,13 @@ fn main() -> Result<(), Box<Error>> {
shall_we_proceed()?; shall_we_proceed()?;
fn shall_we_proceed() -> Result<(), Box<Error>> { fn shall_we_proceed() -> Result<(), Box<dyn Error>> {
println!("Shall we proceed? [Y/n] "); println!("Shall we proceed? [Y/n] ");
_proceed()?; _proceed()?;
fn _proceed() -> Result<(), Box<Error>> { fn _proceed() -> Result<(), Box<dyn Error>> {
let mut input = String::new(); let mut input = String::new();
let stdin = io::stdin(); let stdin = io::stdin();
@ -171,7 +171,7 @@ fn main() -> Result<(), Box<Error>> {
should_export = export_reports_to_output_dir(&mut settings)?; should_export = export_reports_to_output_dir(&mut settings)?;
fn export_reports_to_output_dir(settings: &mut ImportProcessParameters) -> Result<(bool), Box<Error>> { fn export_reports_to_output_dir(settings: &mut ImportProcessParameters) -> Result<(bool), Box<dyn Error>> {
println!("\nThe directory currently selected for exporting reports is: {}", settings.export_path.to_str().unwrap()); println!("\nThe directory currently selected for exporting reports is: {}", settings.export_path.to_str().unwrap());
@ -182,7 +182,7 @@ fn main() -> Result<(), Box<Error>> {
let choice = _export(settings)?; let choice = _export(settings)?;
fn _export(settings: &mut ImportProcessParameters) -> Result<(bool), Box<Error>> { fn _export(settings: &mut ImportProcessParameters) -> Result<(bool), Box<dyn Error>> {
let mut input = String::new(); let mut input = String::new();
let stdin = io::stdin(); let stdin = io::stdin();

View File

@ -31,7 +31,7 @@ impl Transaction {
ars: &HashMap<u32, ActionRecord>, ars: &HashMap<u32, ActionRecord>,
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
) -> Result<TxType, Box<Error>> { ) -> Result<TxType, Box<dyn Error>> {
if self.action_record_idx_vec.len() == 1 { if self.action_record_idx_vec.len() == 1 {
Ok(TxType::Flow) Ok(TxType::Flow)
@ -112,7 +112,7 @@ impl Transaction {
ars: &HashMap<u32, ActionRecord>, ars: &HashMap<u32, ActionRecord>,
raw_accts: &HashMap<u16, RawAccount>, raw_accts: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account> acct_map: &HashMap<u16, Account>
) -> Result<(u16, u16), Box<Error>> { ) -> Result<(u16, u16), Box<dyn Error>> {
assert_eq!(self.transaction_type(ars, raw_accts, acct_map)?, TxType::Exchange, assert_eq!(self.transaction_type(ars, raw_accts, acct_map)?, TxType::Exchange,
"This can only be called on exchange transactions."); "This can only be called on exchange transactions.");
@ -152,7 +152,7 @@ impl Transaction {
raw_acct_map: &HashMap<u16, RawAccount>, raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>, acct_map: &HashMap<u16, Account>,
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Result<Vec<Rc<Movement>>, Box<Error>> { ) -> Result<Vec<Rc<Movement>>, Box<dyn Error>> {
let mut flow_or_outgoing_exchange_movements = [].to_vec(); let mut flow_or_outgoing_exchange_movements = [].to_vec();