Browse Source

buggy add

db-refactoring
Coin de Gamma 4 months ago
parent
commit
1156f71ab8
  1. 17
      src/db.rs
  2. 7
      src/main.rs

17
src/db.rs

@ -1,7 +1,7 @@
use std::collections::HashSet;
use std::fs;
use std::io::{self, BufRead};
use std::io::{self, Write, BufRead};
pub struct DB {
@ -29,9 +29,18 @@ impl DB {
Ok(result)
}
//pub fn dump(&self) {
// TODO: implement
//}
pub fn dump(&self, path: &str) -> io::Result<()> {
let mut file = fs::OpenOptions::new()
.write(true)
.append(false)
.open(path)?;
for id in self.items.iter() {
writeln!(file, "{}", id)?;
}
Ok(())
}
}

7
src/main.rs

@ -69,12 +69,9 @@ fn add(id: &String) -> io::Result<()> {
format!("Dublicate item id: {}. Item id's must be unique.", id)
))
}
let mut file = fs::OpenOptions::new()
.write(true)
.append(true)
.open(STORAGE_PATH)?;
writeln!(file, "{}", id)?;
db.dump(STORAGE_PATH)?;
Ok(())
}

Loading…
Cancel
Save