Added functions to the trait
This commit is contained in:
parent
8ecab2c182
commit
6b1d5635c6
2 changed files with 30 additions and 1 deletions
18
src/cache.rs
18
src/cache.rs
|
@ -6,6 +6,7 @@ use std::error::Error;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use crate::traits::CalDavSource;
|
use crate::traits::CalDavSource;
|
||||||
use crate::Calendar;
|
use crate::Calendar;
|
||||||
|
@ -88,6 +89,23 @@ impl CalDavSource for Cache {
|
||||||
.collect()
|
.collect()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_calendar(&self, url: Url) -> Option<&Calendar> {
|
||||||
|
for cal in &self.data.calendars {
|
||||||
|
if cal.url() == &url {
|
||||||
|
return Some(cal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
async fn get_calendar_mut(&mut self, url: Url) -> Option<&mut Calendar> {
|
||||||
|
for cal in &mut self.data.calendars {
|
||||||
|
if cal.url() == &url {
|
||||||
|
return Some(cal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use crate::Calendar;
|
use crate::Calendar;
|
||||||
|
|
||||||
|
@ -9,8 +10,18 @@ pub trait CalDavSource {
|
||||||
/// Returns the current calendars that this source contains
|
/// Returns the current calendars that this source contains
|
||||||
/// This function may trigger an update (that can be a long process, or that can even fail, e.g. in case of a remote server)
|
/// This function may trigger an update (that can be a long process, or that can even fail, e.g. in case of a remote server)
|
||||||
async fn get_calendars(&self) -> Result<&Vec<Calendar>, Box<dyn Error>>;
|
async fn get_calendars(&self) -> Result<&Vec<Calendar>, Box<dyn Error>>;
|
||||||
|
|
||||||
/// Returns the current calendars that this source contains
|
/// Returns the current calendars that this source contains
|
||||||
/// This function may trigger an update (that can be a long process, or that can even fail, e.g. in case of a remote server)
|
/// This function may trigger an update (that can be a long process, or that can even fail, e.g. in case of a remote server)
|
||||||
async fn get_calendars_mut(&mut self) -> Result<Vec<&mut Calendar>, Box<dyn Error>>;
|
async fn get_calendars_mut(&mut self) -> Result<Vec<&mut Calendar>, Box<dyn Error>>;
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// TODO: find a better search key (do calendars have a unique ID?)
|
||||||
|
// TODO: search key should be a reference
|
||||||
|
//
|
||||||
|
/// Returns the calendar matching the URL
|
||||||
|
async fn get_calendar(&self, url: Url) -> Option<&Calendar>;
|
||||||
|
/// Returns the calendar matching the URL
|
||||||
|
async fn get_calendar_mut(&mut self, url: Url) -> Option<&mut Calendar>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue