diff --git a/src/db.rs b/src/db.rs index e803463..48210fd 100644 --- a/src/db.rs +++ b/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(()) + } } diff --git a/src/main.rs b/src/main.rs index e43a644..bd58cab 100644 --- a/src/main.rs +++ b/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(()) }