+ use std::error::Error;
+ use std::io;
+ use std::process;
+
+ //use chrono::prelude::*;
+
+ use serde::Deserialize;
+
+ // By default, struct field names are deserialized based on the position of
+ // a corresponding field in the CSV data's header record.
+ #[derive(Debug, Deserialize)]
+ #[serde(rename_all = "PascalCase")]
+ struct IcaTransaction {
+ datum: String,
+ text: String,
+ typ: String,
+ budgetgrupp: String,
+ belopp: String,
+ saldo: Option<String>,
+ }
+
+ // By default, struct field names are deserialized based on the position of
+ // a corresponding field in the CSV data's header record.
+ #[derive(Debug, Deserialize)]
+ #[serde(rename_all = "PascalCase")]
+ struct GCTransaction {
+ date: String,
+ transaction_id: String,
+ number: String,
+ description: Option<String>,
+ notes: Option<String>,
+ commodity_currency: Option<String>,
+ void_reason: Option<String>,
+ action: Option<String>,
+ memo: Option<String>,
+ full_account_name: Option<String>,
+ account_name: Option<String>,
+ amount_with_sym: Option<String>,
+ amount_num: Option<String>,
+ reconcile: Option<String>,
+ reconcile_date: Option<String>,
+ rate_price: Option<String>,
+ }
+
+ fn example() -> Result<(), Box<dyn Error>> {
+ let mut rdr = csv::ReaderBuilder::new()
+ .has_headers(true)
+ .delimiter(b';')
+ .from_path("konto.csv")?;
+
+ let mut wtr = csv::Writer::from_writer(io::stdout());
+
+ //let mut wtr = csv::WriterBuilder::from_writer(&self, wtr)
+
+ // Write headers manually.
+ wtr.write_record(&[
+ "Date",
+ "Transaction ID",
+ "Number",
+ "Description",
+ "Notes",
+ "Commodity/Currency",
+ "Void Reason",
+ "Action",
+ "Memo",
+ "Full Account Name",
+ "Account Name",
+ "Amount With Sym.",
+ "Amount Num",
+ "Reconcile",
+ "Reconcile Date",
+ "Rate/Price",
+ ])?;
+ for result in rdr.deserialize() {
+ // Notice that we need to provide a type hint for automatic
+ // deserialization.
+ let record: IcaTransaction = result?;
+ println!("{:?}", record);
+ }
+
+ Ok(())
+ }
+
+ fn main() {
+ if let Err(err) = example() {
+ println!("error running example: {}", err);
+ process::exit(1);
+ }
+ }