Added a function

This commit is contained in:
daladim 2021-12-19 18:49:47 +01:00
parent 3d142edf3e
commit 94b3bb27ba
2 changed files with 15 additions and 0 deletions

View file

@ -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)
}

View file

@ -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>;