Browse Source

Added some TODOs in the code

master
Julio Biason 5 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 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,

10
src/eventlist/eventlist.rs

@ -29,25 +29,30 @@ static FILENAME: &str = "events.toml";
#[derive(Serialize, Deserialize, Debug)]
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> {
index: usize,
max: usize,
list: &'a Vec<Event>,
}
// 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();

5
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);

Loading…
Cancel
Save