summaryrefslogtreecommitdiffstats
path: root/cli/src/model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/model.rs')
-rw-r--r--cli/src/model.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/cli/src/model.rs b/cli/src/model.rs
index b0dab7a..c93897f 100644
--- a/cli/src/model.rs
+++ b/cli/src/model.rs
@@ -4,6 +4,8 @@ use std::convert::AsRef;
use std::fs;
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
+use std::str::FromStr;
+use structopt::StructOpt;
use twox_hash::XxHash64;
type Account = String;
@@ -12,22 +14,35 @@ type Category = String;
#[derive(Debug)]
#[derive(Hash)]
#[derive(Deserialize, Serialize)]
+#[derive(StructOpt)]
pub enum TransactionKind {
Expense,
Income,
//TODO Transfer,
}
+impl FromStr for TransactionKind {
+ type Err = String;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "expense" => Ok(TransactionKind::Expense),
+ "income" => Ok(TransactionKind::Income),
+ _ => Err(format!("Unknown transaction kind: {:?}", s)),
+ }
+ }
+}
+
#[derive(Debug)]
#[derive(Hash)]
#[derive(Deserialize, Serialize)]
pub struct Transaction {
- description: String,
- category: Category,
- amount: Decimal,
- kind: TransactionKind,
- from: Account,
- to: Account,
+ pub description: String,
+ pub category: Category,
+ pub amount: Decimal,
+ pub kind: TransactionKind,
+ pub from: Account,
+ pub to: Account,
}
#[derive(Debug)]