diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-07-29 00:37:27 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-07-29 00:37:27 +0200 |
| commit | b2820ad0c0a6c8a116c8d7eb09eccb9838a9e30e (patch) | |
| tree | 0e85ae2f4aa93488072e4a45002b5b9b5db8aaf5 /cli/src | |
| parent | 7f84d10288deffcbf4cc71511f5605a3442e4955 (diff) | |
| download | money-b2820ad0c0a6c8a116c8d7eb09eccb9838a9e30e.tar.gz | |
move id func and result
Diffstat (limited to 'cli/src')
| -rw-r--r-- | cli/src/main.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs index 8f9cccf..f853bd2 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -72,11 +72,8 @@ impl Store { fn write(&self) -> std::io::Result<()> { for post in &self.posts { - let mut h = XxHash64::default(); - post.hash(&mut h); - let h = h.finish(); let mut path = self.root.clone(); - path.push(format!("{}", h)); + path.push(format!("{}", post.id())); post.write(&path)?; } Ok(()) @@ -99,6 +96,12 @@ impl Post { fn open<P: AsRef<Path>>(p: &P) -> Option<Self> { fs::read_to_string(p).ok().as_ref().and_then(|s| serde_json::from_str(s).ok()) } + + fn id(&self) -> u64 { + let mut h = XxHash64::default(); + self.hash(&mut h); + h.finish() + } } fn main() { @@ -113,5 +116,5 @@ fn main() { // post.write(&"test").unwrap(); let store = Store::open(PathBuf::from("store")).unwrap(); // println!("{:#?}", store); - store.write(); + store.write().unwrap(); } |
