From 750ac56977cd08d850cf902c8c8070512ecf484f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 29 Jul 2021 15:42:12 +0200 Subject: table output and show command --- cli/src/transaction.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cli/src/transaction.rs') diff --git a/cli/src/transaction.rs b/cli/src/transaction.rs index 117edfb..8e33aa4 100644 --- a/cli/src/transaction.rs +++ b/cli/src/transaction.rs @@ -2,10 +2,12 @@ use chrono::naive::NaiveDate; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use std::convert::AsRef; +use std::fmt; use std::fs; use std::hash::{Hash, Hasher}; use std::path::Path; use structopt::StructOpt; +use tabled::Tabled; use twox_hash::XxHash64; pub(crate) type Account = String; @@ -33,9 +35,19 @@ impl std::str::FromStr for TransactionKind { } } +impl fmt::Display for TransactionKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + TransactionKind::Expense => write!(f, "expense"), + TransactionKind::Income => write!(f, "income"), + } + } +} + #[derive(Debug)] #[derive(Hash)] #[derive(Deserialize, Serialize)] +#[derive(Tabled)] pub struct Transaction { pub description: String, pub date: NaiveDate, -- cgit v1.2.1