From cc393ce2c0ee20d5c1ada2d7d57db303a5b58ceb Mon Sep 17 00:00:00 2001 From: itsscb Date: Thu, 24 Jul 2025 11:53:53 +0200 Subject: [PATCH] feat: add basic errors --- src/lib.rs | 9 +++++++-- src/main.rs | 15 +++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b65ac1f..9864d5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,9 +19,14 @@ impl App { Self::default() } - pub fn add(&mut self, item: Item) { + pub fn add(&mut self, item: Item) -> Result<()> { self.logs.push(item); - let _ = self.save(); + self.save() + } + + pub fn remove>(&mut self, id: T) -> Result<()> { + self.logs.retain(|i| i.id() != id.as_ref()); + self.save() } pub fn save(&self) -> Result<()> { diff --git a/src/main.rs b/src/main.rs index badbbbb..b856a3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,15 @@ -use lw::App; +use std::error::Error; -fn main() { +use lw::{App, log::Item}; + +fn main() -> Result<(), Box> { let mut app = App::default(); - app.add("hello_world".into()); - app.save().unwrap(); + let item = Item::from("hello_world"); + let id = item.id(); + app.add(item)?; println!("{app:?}"); + app.remove(id)?; + app.save()?; + println!("{app:?}"); + Ok(()) }