diff --git a/src/data/calendar.rs b/src/data/calendar.rs index 94c2fa9..b4d7482 100644 --- a/src/data/calendar.rs +++ b/src/data/calendar.rs @@ -1,24 +1,21 @@ -use crate::data::TaskView; - -/// A Caldav Calendar -pub struct Calendar { - name: String, - - tasks: Vec, -} - -impl Calendar { - pub fn name() -> String { - self.name - } - - pub fn tasks() -> Vec { - self.tasks - } -} - -impl Drop for Calendar { - fn drop(&mut self) { - // TODO: display a warning in case some TaskViews still have a refcount > 0 - } -} +use crate::data::Task; + +/// A Caldav Calendar +pub struct Calendar { + name: String, + + tasks: Vec, +} + +impl Calendar { + pub fn name(&self) -> String { + self.name + } + + pub fn tasks(&self) -> Vec<&Task> { + self.tasks + .iter() + .map(|t| &t) + .collect() + } +} diff --git a/src/data/mod.rs b/src/data/mod.rs index 05eb0d8..9e14d79 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -12,16 +12,11 @@ pub use calendar::Calendar; pub use tasks::Task; use client::Client; -// TODO: consider using references here -// (there will be no issue with still-borrowed-data when the DataSource is destroyed, but will it play well with sync stuff?) -type CalendarView = Arc; -type TaskView = Arc; - /// A Caldav data source pub struct DataSource { client: Option, - calendars: Vec + calendars: Vec } impl DataSource { @@ -43,13 +38,10 @@ impl DataSource { // TODO: how to handle conflicts? } - pub fn calendars(&self) -> Vec { + pub fn calendars(&self) -> Vec<&Calendar> { self.calendars - } -} - -impl Drop for DataSource { - fn drop(&mut self) { - // TODO: display a warning in case some CalendarViews still have a refcount > 0 + .iter() + .map(|c| &c) + .collect() } }