Browse Source

Changed signature of insert_calendar

github_actions
daladim 5 years ago
parent
commit
f18b1acc0f
  1. 7
      src/cache.rs
  2. 4
      src/client.rs
  3. 4
      src/traits.rs

7
src/cache.rs

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

4
src/client.rs

@ -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!();
} }
} }

4
src/traits.rs

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

Loading…
Cancel
Save