Compare commits

..

No commits in common. "cc393ce2c0ee20d5c1ada2d7d57db303a5b58ceb" and "1b945d09b11cba818832c81ecef538cc7ca46d09" have entirely different histories.

4 changed files with 6 additions and 26 deletions

View File

@ -7,4 +7,3 @@ edition = "2024"
chrono = { version = "0.4.41", features = ["serde"] }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.141"
uuid = { version = "1.17.0", features = ["serde", "v4"] }

View File

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

View File

@ -1,10 +1,8 @@
use chrono::{DateTime, Local};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct Item {
id: Uuid,
content: String,
created: DateTime<Local>,
modified: DateTime<Local>,
@ -19,17 +17,12 @@ impl Item {
self.content = content;
self.modified = Local::now();
}
pub fn id(&self) -> String {
self.id.to_string()
}
}
impl Default for Item {
fn default() -> Self {
let now = Local::now();
Self {
id: Uuid::new_v4(),
content: String::new(),
created: now,
modified: now,

View File

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