Browse Source

Expose the events iterator instead of creating on of our own

master
Julio Biason 4 years ago
parent
commit
d3d7b8fa31
  1. 34
      README.md
  2. 31
      src/eventlist.rs

34
README.md

@ -12,44 +12,12 @@ tell you that you have 15 days up to it.
## Commands
* Listing events: `tu`
* Adding new events: `tu add YYYY-MM-DD 'description'`
* Optional: set a time for the event: `tu add YYYY-MM-DD 'description' --time HH:MM`
* Listing events: `tu`
* Removing events: When you add an event, it will show up a small code for
that event; you can remove it with `tu rm EVENTID`
## TODO
### Visual/Interface
- [ ] Option to remove events
- [ ] Option to remove every "Over" event"
- [ ] Pretty output like `bat`
### Internal changes
- [ ] `Date` and `Time` constructors
- [ ] Change `due` match to use guardians and remove the internal match
- [ ] Remove `fmt::Display` from `Event`; the display should be in the
main/interface layer
- [ ] Move the app "db" to a fixed space
- [ ] Create a proper "repository" for the event list
- [ ] Replace toml; the resulting file, although simple to use internally, is
hard to read due our data format; we can either remove `serde` completely
or write our own `Serializer`/`Deserializer` interfaces
- [ ] Tests
### Done
- [x] Add unique identifier for each event
- [x] List events
- [x] Add Events with time
- [x] List events with time
- [x] Sort events by ETA
- [x] Replace `dbg!` with [env_logger](https://crates.io/crates/env_logger)
(reasoning: Although `dbg!` is nice and dandy, it can't be disabled, and
that's bad UI)
## License
GNU AFFERO GENERAL PUBLIC LICENSE, Version 3.

31
src/eventlist.rs

@ -38,13 +38,6 @@ pub struct EventList {
events: Vec<Event>,
}
// TODO expose Vec iterator?
pub struct EventListIterator<'a> {
index: usize,
max: usize,
list: &'a Vec<Event>,
}
#[derive(Debug)]
pub enum EventListError {
InvalidDate,
@ -74,14 +67,11 @@ impl From<toml::de::Error> for EventListError {
}
}
// TODO separate business rule from repository
impl EventList {
// TODO hide this
pub fn load() -> Result<Self, EventListError> {
if let Ok(mut fp) = File::open(EventList::event_file()?) {
let mut content = String::new();
fp.read_to_string(&mut content)?;
// TODO remove toml
let data = toml::from_str(&content)?;
Ok(data)
} else {
@ -148,26 +138,9 @@ impl EventList {
impl<'a> IntoIterator for &'a EventList {
type Item = &'a Event;
type IntoIter = EventListIterator<'a>;
type IntoIter = std::slice::Iter<'a, Event>;
fn into_iter(self) -> Self::IntoIter {
EventListIterator {
index: 0,
max: self.events.len(),
list: &self.events,
}
}
}
impl<'a> Iterator for EventListIterator<'a> {
type Item = &'a Event;
fn next(&mut self) -> Option<&'a Event> {
if self.index >= self.max {
None
} else {
self.index += 1;
Some(&self.list[self.index - 1])
}
self.events.iter()
}
}

Loading…
Cancel
Save