diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-07-29 00:29:40 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-07-29 00:29:40 +0200 |
| commit | 157790ff3452be04b6a14c1bec7aab821a4a8725 (patch) | |
| tree | 7222496a802c16106b1a1c7b9d177a630da2dcb2 /cli/src | |
| parent | 1bb5514fa9885a4a186659c4084aa7da091b9b1a (diff) | |
| download | money-157790ff3452be04b6a14c1bec7aab821a4a8725.tar.gz | |
hash posts
Diffstat (limited to 'cli/src')
| -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(); } |
