feat: add basic errors

This commit is contained in:
itsscb 2025-07-24 11:53:53 +02:00
parent 7a8d6e0e74
commit cc393ce2c0
2 changed files with 18 additions and 6 deletions

View File

@ -19,9 +19,14 @@ impl App {
Self::default() Self::default()
} }
pub fn add(&mut self, item: Item) { pub fn add(&mut self, item: Item) -> Result<()> {
self.logs.push(item); self.logs.push(item);
let _ = self.save(); self.save()
}
pub fn remove<T: AsRef<str>>(&mut self, id: T) -> Result<()> {
self.logs.retain(|i| i.id() != id.as_ref());
self.save()
} }
pub fn save(&self) -> Result<()> { pub fn save(&self) -> Result<()> {

View File

@ -1,8 +1,15 @@
use lw::App; use std::error::Error;
fn main() { use lw::{App, log::Item};
fn main() -> Result<(), Box<dyn Error>> {
let mut app = App::default(); let mut app = App::default();
app.add("hello_world".into()); let item = Item::from("hello_world");
app.save().unwrap(); let id = item.id();
app.add(item)?;
println!("{app:?}"); println!("{app:?}");
app.remove(id)?;
app.save()?;
println!("{app:?}");
Ok(())
} }