Browse Source

path in db

db-refactoring
Coin de Gamma 4 months ago
parent
commit
433c09c7a5
  1. 10
      src/db.rs
  2. 2
      src/main.rs

10
src/db.rs

@ -53,7 +53,8 @@ impl Ord for Item {
}
pub struct DB {
pub items: HashSet::<Item>
pub items: HashSet::<Item>,
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)?;

2
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(())
}

Loading…
Cancel
Save