diff --git a/src/cache.rs b/src/cache.rs index 679a37c..dea0d55 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -183,12 +183,13 @@ impl CalDavSource for Cache { self.data.calendars.get(id).map(|arc| arc.clone()) } - async fn insert_calendar(&mut self, new_calendar: CachedCalendar) -> Result<(), Box> { + async fn insert_calendar(&mut self, new_calendar: CachedCalendar) -> Result>, Box> { let id = new_calendar.id().clone(); log::debug!("Inserting local calendar {}", id); - match self.data.calendars.insert(id, Arc::new(Mutex::new(new_calendar))) { + let arc = Arc::new(Mutex::new(new_calendar)); + match self.data.calendars.insert(id, arc.clone()) { Some(_) => Err("Attempt to insert calendar failed: there is alredy such a calendar.".into()), - None => Ok(()) , + None => Ok(arc) , } } } diff --git a/src/client.rs b/src/client.rs index 81bc81a..59ca993 100644 --- a/src/client.rs +++ b/src/client.rs @@ -231,8 +231,8 @@ impl CalDavSource for Client { .map(|cal| cal.clone()) } - async fn insert_calendar(&mut self, new_calendar: RemoteCalendar) -> Result<(), Box> { - Err("Not implemented".into()) + async fn insert_calendar(&mut self, _new_calendar: RemoteCalendar) -> Result>, Box> { + todo!(); } } diff --git a/src/traits.rs b/src/traits.rs index 74859b2..1942a70 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -17,8 +17,8 @@ pub trait CalDavSource { async fn get_calendars(&self) -> Result>>, Box>; /// Returns the calendar matching the ID async fn get_calendar(&self, id: &CalendarId) -> Option>>; - /// Insert a calendar if it did not exist - async fn insert_calendar(&mut self, new_calendar: T) -> Result<(), Box>; + /// Insert a calendar if it did not exist, and return it + async fn insert_calendar(&mut self, new_calendar: T) -> Result>, Box>; } /// This trait contains functions that are common to all calendars