From 433c09c7a51e1117c9fa117420db38f5670cd4e3 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Fri, 6 Sep 2024 12:45:32 +0000 Subject: [PATCH] path in db --- src/db.rs | 10 ++++++---- src/main.rs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/db.rs b/src/db.rs index 8aec813..d446250 100644 --- a/src/db.rs +++ b/src/db.rs @@ -53,7 +53,8 @@ impl Ord for Item { } pub struct DB { - pub items: HashSet:: + pub items: HashSet::, + path: String } impl DB { @@ -72,7 +73,8 @@ impl DB { } } let result = DB { - items: items + items: items, + path: String::from(path) }; Ok(result) } @@ -82,11 +84,11 @@ impl DB { self.items.contains(&item) } - pub fn dump(&self, path: &str) -> io::Result<()> { + pub fn dump(&self) -> io::Result<()> { let mut file = fs::OpenOptions::new() .write(true) .append(false) - .open(path)?; + .open(&self.path)?; for item in self.items.iter() { writeln!(file, "{}", item.id)?; diff --git a/src/main.rs b/src/main.rs index d958211..f2b7aac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ fn add(id: &String) -> io::Result<()> { } db.items.insert(Item::from(id.clone())); - db.dump(&*STORAGE_PATH)?; + db.dump()?; Ok(()) }