Changed signature of insert_calendar

This commit is contained in:
daladim 2021-04-03 09:24:20 +02:00
parent 707d764e6b
commit f18b1acc0f
3 changed files with 8 additions and 7 deletions

View file

@ -183,12 +183,13 @@ impl CalDavSource<CachedCalendar> for Cache {
self.data.calendars.get(id).map(|arc| arc.clone()) self.data.calendars.get(id).map(|arc| arc.clone())
} }
async fn insert_calendar(&mut self, new_calendar: CachedCalendar) -> Result<(), Box<dyn Error>> { async fn insert_calendar(&mut self, new_calendar: CachedCalendar) -> Result<Arc<Mutex<CachedCalendar>>, Box<dyn Error>> {
let id = new_calendar.id().clone(); let id = new_calendar.id().clone();
log::debug!("Inserting local calendar {}", id); 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()), Some(_) => Err("Attempt to insert calendar failed: there is alredy such a calendar.".into()),
None => Ok(()) , None => Ok(arc) ,
} }
} }
} }

View file

@ -231,8 +231,8 @@ impl CalDavSource<RemoteCalendar> for Client {
.map(|cal| cal.clone()) .map(|cal| cal.clone())
} }
async fn insert_calendar(&mut self, new_calendar: RemoteCalendar) -> Result<(), Box<dyn Error>> { async fn insert_calendar(&mut self, _new_calendar: RemoteCalendar) -> Result<Arc<Mutex<RemoteCalendar>>, Box<dyn Error>> {
Err("Not implemented".into()) todo!();
} }
} }

View file

@ -17,8 +17,8 @@ pub trait CalDavSource<T: BaseCalendar> {
async fn get_calendars(&self) -> Result<HashMap<CalendarId, Arc<Mutex<T>>>, Box<dyn Error>>; async fn get_calendars(&self) -> Result<HashMap<CalendarId, Arc<Mutex<T>>>, Box<dyn Error>>;
/// Returns the calendar matching the ID /// Returns the calendar matching the ID
async fn get_calendar(&self, id: &CalendarId) -> Option<Arc<Mutex<T>>>; async fn get_calendar(&self, id: &CalendarId) -> Option<Arc<Mutex<T>>>;
/// Insert a calendar if it did not exist /// Insert a calendar if it did not exist, and return it
async fn insert_calendar(&mut self, new_calendar: T) -> Result<(), Box<dyn Error>>; async fn insert_calendar(&mut self, new_calendar: T) -> Result<Arc<Mutex<T>>, Box<dyn Error>>;
} }
/// This trait contains functions that are common to all calendars /// This trait contains functions that are common to all calendars