#[derive(Debug)] pub struct Record { account: String, currency: String, record_type: String, main_type: String, subcategory: String, price: f64, fee: f64, bonus: f64, name: String, store: Option, date: Date, time: Option, project: Option, note: Option, tags: Option, target: Option, } #[derive(Debug)] struct Date { month: i32, day: i32, year: i32, } impl Record { pub fn new(r: csv::StringRecord) -> Self { Record { account: r[0].to_string(), currency: r[1].to_string(), record_type: r[2].to_string(), main_type: r[3].to_string(), subcategory: r[4].to_string(), price: r[5].parse().unwrap(), fee: r[6].parse().unwrap(), bonus: r[7].parse().unwrap(), name: r[8].to_string(), store: r.get(9).map(|s| s.to_string()), date: { let d = r[10].split('/').collect::>(); Date { month: d[0].parse().unwrap(), day: d[1].parse().unwrap(), year: d[2].parse().unwrap(), } }, time: r.get(11).map(|s| s.to_string()), project: r.get(12).map(|s| s.to_string()), note: r.get(13).map(|s| s.to_string()), tags: r.get(14).map(|s| s.to_string()), target: r.get(15).map(|s| s.to_string()), } } pub fn cal(&self) -> f64 { self.price + self.fee + self.bonus } pub fn record_type(&self) -> &str { self.record_type.as_str() } pub fn project(&self) -> Option { self.project.clone() } pub fn currency(&self) -> String { self.currency.clone() } }