summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-07-29 00:29:40 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-07-29 00:29:40 +0200
commit157790ff3452be04b6a14c1bec7aab821a4a8725 (patch)
tree7222496a802c16106b1a1c7b9d177a630da2dcb2
parent1bb5514fa9885a4a186659c4084aa7da091b9b1a (diff)
downloadmoney-157790ff3452be04b6a14c1bec7aab821a4a8725.tar.gz
hash posts
-rw-r--r--cli/Cargo.lock23
-rw-r--r--cli/Cargo.toml1
-rw-r--r--cli/src/main.rs17
3 files changed, 40 insertions, 1 deletions
diff --git a/cli/Cargo.lock b/cli/Cargo.lock
index fb68e73..b69f6d6 100644
--- a/cli/Cargo.lock
+++ b/cli/Cargo.lock
@@ -15,6 +15,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
+name = "cfg-if"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
+
+[[package]]
name = "itoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -27,6 +33,7 @@ dependencies = [
"rust_decimal",
"serde",
"serde_json",
+ "twox-hash",
]
[[package]]
@@ -106,6 +113,12 @@ dependencies = [
]
[[package]]
+name = "static_assertions"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
+
+[[package]]
name = "syn"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -117,6 +130,16 @@ dependencies = [
]
[[package]]
+name = "twox-hash"
+version = "1.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59"
+dependencies = [
+ "cfg-if",
+ "static_assertions",
+]
+
+[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 1535896..bdaa3e3 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -9,3 +9,4 @@ edition = "2018"
rust_decimal = { version = "1.15.0", features = ["serde-arbitrary-precision"] }
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
+twox-hash = { version = "1.6.0", default-features = false }
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();
}