From fcd36378045fd8d0f500cd1f9335a819184a77b1 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Fri, 15 May 2020 20:15:08 -0300 Subject: [PATCH] Added some TODOs in the code --- src/eventlist/event.rs | 2 ++ src/eventlist/eventlist.rs | 10 +++++++++- src/main.rs | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/eventlist/event.rs b/src/eventlist/event.rs index 3ce55d2..b15a189 100644 --- a/src/eventlist/event.rs +++ b/src/eventlist/event.rs @@ -26,6 +26,7 @@ use serde_derive::Deserialize; use serde_derive::Serialize; use uuid::Uuid; +// TODO constructors #[derive(Serialize, Deserialize, Debug)] pub struct Date { year: i32, @@ -33,6 +34,7 @@ pub struct Date { day: u32, } +// TODO constructors #[derive(Serialize, Deserialize, Debug)] pub struct Time { hour: u32, diff --git a/src/eventlist/eventlist.rs b/src/eventlist/eventlist.rs index 5617836..41462eb 100644 --- a/src/eventlist/eventlist.rs +++ b/src/eventlist/eventlist.rs @@ -29,25 +29,30 @@ static FILENAME: &str = "events.toml"; #[derive(Serialize, Deserialize, Debug)] pub struct EventList { - pub events: Vec, + pub events: Vec, // TODO remove pub } +// XXX new type? pub struct EventList(Vec); +// TODO expose Vec iterator? pub struct EventListIterator<'a> { index: usize, max: usize, list: &'a Vec, } +// TODO separate business rule from repository impl EventList { fn empty() -> Self { Self { events: Vec::new() } } + // TODO hide this pub fn load() -> Self { if let Ok(mut fp) = File::open(FILENAME) { let mut content = String::new(); fp.read_to_string(&mut content) .expect("Your event file is corrupted"); + // TODO remove toml toml::from_str(&content).unwrap_or(EventList::empty()) } else { EventList::empty() @@ -59,7 +64,10 @@ impl EventList { self.events.sort(); } + // TODO turn this into the destructor + // TODO if so, track changes pub fn save(&self) { + // TODO remove toml let content = toml::to_string(&self).unwrap(); if let Ok(mut fp) = File::create(FILENAME) { fp.write_all(content.as_bytes()).unwrap(); diff --git a/src/main.rs b/src/main.rs index a663968..2488b4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,12 +40,13 @@ fn main() { } fn list() { - let event_list = EventList::load(); + let event_list = EventList::load(); // TODO hide this for record in event_list.into_iter() { - println!("{}", record); + println!("{}", record); // TODO remove display } } +// TODO business rule (should be in EventList) fn add_with_date(description: &str, date: &str) { let event = Event::new_on_date(description, date); add_event(event);