feat: add basic errors
This commit is contained in:
parent
7a8d6e0e74
commit
cc393ce2c0
@ -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<T: AsRef<str>>(&mut self, id: T) -> Result<()> {
|
||||
self.logs.retain(|i| i.id() != id.as_ref());
|
||||
self.save()
|
||||
}
|
||||
|
||||
pub fn save(&self) -> Result<()> {
|
||||
|
15
src/main.rs
15
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<dyn Error>> {
|
||||
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(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user