Browse Source

Added some TODOs in the code

master
Julio Biason 4 years ago
parent
commit
fcd3637804
  1. 2
      src/eventlist/event.rs
  2. 10
      src/eventlist/eventlist.rs
  3. 5
      src/main.rs

2
src/eventlist/event.rs

@ -26,6 +26,7 @@ use serde_derive::Deserialize;
use serde_derive::Serialize; use serde_derive::Serialize;
use uuid::Uuid; use uuid::Uuid;
// TODO constructors
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Date { pub struct Date {
year: i32, year: i32,
@ -33,6 +34,7 @@ pub struct Date {
day: u32, day: u32,
} }
// TODO constructors
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Time { pub struct Time {
hour: u32, hour: u32,

10
src/eventlist/eventlist.rs

@ -29,25 +29,30 @@ static FILENAME: &str = "events.toml";
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct EventList { pub struct EventList {
pub events: Vec<Event>, pub events: Vec<Event>, // TODO remove pub
} }
// XXX new type? pub struct EventList(Vec<Event>);
// TODO expose Vec iterator?
pub struct EventListIterator<'a> { pub struct EventListIterator<'a> {
index: usize, index: usize,
max: usize, max: usize,
list: &'a Vec<Event>, list: &'a Vec<Event>,
} }
// TODO separate business rule from repository
impl EventList { impl EventList {
fn empty() -> Self { fn empty() -> Self {
Self { events: Vec::new() } Self { events: Vec::new() }
} }
// TODO hide this
pub fn load() -> Self { pub fn load() -> Self {
if let Ok(mut fp) = File::open(FILENAME) { if let Ok(mut fp) = File::open(FILENAME) {
let mut content = String::new(); let mut content = String::new();
fp.read_to_string(&mut content) fp.read_to_string(&mut content)
.expect("Your event file is corrupted"); .expect("Your event file is corrupted");
// TODO remove toml
toml::from_str(&content).unwrap_or(EventList::empty()) toml::from_str(&content).unwrap_or(EventList::empty())
} else { } else {
EventList::empty() EventList::empty()
@ -59,7 +64,10 @@ impl EventList {
self.events.sort(); self.events.sort();
} }
// TODO turn this into the destructor
// TODO if so, track changes
pub fn save(&self) { pub fn save(&self) {
// TODO remove toml
let content = toml::to_string(&self).unwrap(); let content = toml::to_string(&self).unwrap();
if let Ok(mut fp) = File::create(FILENAME) { if let Ok(mut fp) = File::create(FILENAME) {
fp.write_all(content.as_bytes()).unwrap(); fp.write_all(content.as_bytes()).unwrap();

5
src/main.rs

@ -40,12 +40,13 @@ fn main() {
} }
fn list() { fn list() {
let event_list = EventList::load(); let event_list = EventList::load(); // TODO hide this
for record in event_list.into_iter() { 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) { fn add_with_date(description: &str, date: &str) {
let event = Event::new_on_date(description, date); let event = Event::new_on_date(description, date);
add_event(event); add_event(event);

Loading…
Cancel
Save