Browse Source

Added a function

master
daladim 4 years ago
parent
commit
94b3bb27ba
  1. 12
      src/calendar/cached_calendar.rs
  2. 3
      src/traits.rs

12
src/calendar/cached_calendar.rs

@ -134,6 +134,14 @@ impl CachedCalendar {
)
}
/// The non-async version of [`Self::get_items_mut`]
pub fn get_items_mut_sync(&mut self) -> Result<HashMap<Url, &mut Item>, Box<dyn Error>> {
Ok(self.items.iter_mut()
.map(|(url, item)| (url.clone(), item))
.collect()
)
}
/// The non-async version of [`Self::get_item_by_url`]
pub fn get_item_by_url_sync<'a>(&'a self, url: &Url) -> Option<&'a Item> {
self.items.get(url)
@ -253,6 +261,10 @@ impl CompleteCalendar for CachedCalendar {
self.get_items_sync()
}
async fn get_items_mut(&mut self) -> Result<HashMap<Url, &mut Item>, Box<dyn Error>> {
self.get_items_mut_sync()
}
async fn get_item_by_url<'a>(&'a self, url: &Url) -> Option<&'a Item> {
self.get_item_by_url_sync(url)
}

3
src/traits.rs

@ -115,6 +115,9 @@ pub trait CompleteCalendar : BaseCalendar {
/// Returns all items that this calendar contains
async fn get_items(&self) -> Result<HashMap<Url, &Item>, Box<dyn Error>>;
/// Returns all items that this calendar contains
async fn get_items_mut(&mut self) -> Result<HashMap<Url, &mut Item>, Box<dyn Error>>;
/// Returns a particular item
async fn get_item_by_url<'a>(&'a self, url: &Url) -> Option<&'a Item>;

Loading…
Cancel
Save