From 29f84a30d3d794dee37981795461ef833d09364d Mon Sep 17 00:00:00 2001 From: scoobybejesus Date: Fri, 27 Nov 2020 12:10:50 -0500 Subject: [PATCH] CSV Import: removed Options, cloning and unwrapping. --- src/crptls_lib/csv_import_accts_txns.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/crptls_lib/csv_import_accts_txns.rs b/src/crptls_lib/csv_import_accts_txns.rs index 4d09bb2..499702b 100644 --- a/src/crptls_lib/csv_import_accts_txns.rs +++ b/src/crptls_lib/csv_import_accts_txns.rs @@ -51,20 +51,20 @@ fn import_accounts( ) -> Result<(), Box> { let header1 = rdr.headers()?.clone(); // account_num - let mut header2: Option = None; // name - let mut header3: Option = None; // ticker + let mut header2: csv::StringRecord = csv::StringRecord::new(); // name + let mut header3: csv::StringRecord = csv::StringRecord::new(); // ticker let header4: csv::StringRecord; // is_margin // Account Creation loop. With rdr.has_headers() set to true above, the first record here is the second row of the CSV for result in rdr.records() { // This initial iteration through records will break after the 4th row, after accounts have been created let record = result?; - if header2 == None { - header2 = Some(record.clone()); + if header2.len() == 0 { + header2 = record.clone(); continue // After header2 is set, continue to next record } - else if header3 == None { - header3 = Some(record.clone()); + else if header3.len() == 0 { + header3 = record.clone(); continue // After header3 is set, continue to next record } else { @@ -97,8 +97,8 @@ The next column's value should be 2, then 3, etc, until the final account)."; } let ind = idx+3; // Add three because the idx skips the first three 'key' columns - let name:String = header2.clone().unwrap()[ind].trim().to_string(); - let ticker:String = header3.clone().unwrap()[ind].trim().to_string(); // no .to_uppercase() b/c margin... + let name:String = header2[ind].trim().to_string(); + let ticker:String = header3[ind].trim().to_string(); // no .to_uppercase() b/c margin... let margin_string = &header4.clone()[ind]; let is_margin:bool = match margin_string.trim().to_lowercase().as_str() {