diff options
Diffstat (limited to 'cli/src/main.rs')
| -rw-r--r-- | cli/src/main.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs index 9ab5a55..656107d 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -2,12 +2,15 @@ use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use std::convert::{AsRef, TryFrom}; use std::fs; +use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; +use twox_hash::XxHash64; type Account = String; type Category = String; #[derive(Debug)] +#[derive(Hash)] #[derive(Deserialize, Serialize)] enum TransactionKind { Expense, @@ -16,6 +19,7 @@ enum TransactionKind { } #[derive(Debug)] +#[derive(Hash)] #[derive(Deserialize, Serialize)] struct Transaction { description: String, @@ -27,6 +31,7 @@ struct Transaction { } #[derive(Debug)] +#[derive(Hash)] #[derive(Deserialize, Serialize)] struct Post { transaction: Transaction, @@ -63,6 +68,15 @@ impl Store { } Some(res) } + + fn write(&self) { + for post in &self.posts { + let mut h = XxHash64::default(); + post.hash(&mut h); + let file = h.finish(); + println!("{}: {:?}", file, post); + } + } } impl Post { @@ -94,5 +108,6 @@ fn main() { // }); // post.write(&"test").unwrap(); let store = Store::open(PathBuf::from("store")).unwrap(); - println!("{:#?}", store); + // println!("{:#?}", store); + store.write(); } |
