From b2820ad0c0a6c8a116c8d7eb09eccb9838a9e30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 29 Jul 2021 00:37:27 +0200 Subject: move id func and result --- cli/src/main.rs | 13 ++++++++----- 1 file 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: &P) -> Option { 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(); } -- cgit v1.2.1