[provider] Renamed server -> remote

This commit is contained in:
daladim 2021-03-22 22:39:50 +01:00
parent 647199af93
commit c46222c8c7
2 changed files with 16 additions and 17 deletions

View file

@ -11,17 +11,16 @@ use crate::traits::PartialCalendar;
use crate::Item; use crate::Item;
use crate::item::ItemId; use crate::item::ItemId;
/// A data source that combines two `CalDavSources` (usually a server and a local cache), which is able to sync both sources. /// A data source that combines two `CalDavSources` (usually a server and a local cache), which is able to sync both sources.
pub struct Provider<L, T, S, U> pub struct Provider<L, T, R, U>
where where
L: CalDavSource<T>, L: CalDavSource<T>,
T: CompleteCalendar, T: CompleteCalendar,
S: CalDavSource<U>, R: CalDavSource<U>,
U: PartialCalendar + Sync + Send, U: PartialCalendar + Sync + Send,
{ {
/// The remote server /// The remote source (usually a server)
server: S, remote: R,
/// The local cache /// The local cache
local: L, local: L,
@ -29,25 +28,25 @@ where
phantom_u: PhantomData<U>, phantom_u: PhantomData<U>,
} }
impl<L, T, S, U> Provider<L, T, S, U> impl<L, T, R, U> Provider<L, T, R, U>
where where
L: CalDavSource<T>, L: CalDavSource<T>,
T: CompleteCalendar, T: CompleteCalendar,
S: CalDavSource<U>, R: CalDavSource<U>,
U: PartialCalendar + Sync + Send, U: PartialCalendar + Sync + Send,
{ {
/// Create a provider. /// Create a provider.
/// ///
/// `server` is usually a [`Client`](crate::client::Client), `local` is usually a [`Cache`](crate::cache::Cache). /// `remote` is usually a [`Client`](crate::client::Client), `local` is usually a [`Cache`](crate::cache::Cache).
/// However, both can be interchangeable. The only difference is that `server` always wins in case of a sync conflict /// However, both can be interchangeable. The only difference is that `remote` always wins in case of a sync conflict
pub fn new(server: S, local: L) -> Self { pub fn new(remote: R, local: L) -> Self {
Self { server, local, Self { remote, local,
phantom_t: PhantomData, phantom_u: PhantomData, phantom_t: PhantomData, phantom_u: PhantomData,
} }
} }
/// Returns the data source described as the `server` /// Returns the data source described as the `server`
pub fn server(&self) -> &S { &self.server } pub fn remote(&self) -> &R { &self.remote }
/// Returns the data source described as the `local` /// Returns the data source described as the `local`
pub fn local(&self) -> &L { &self.local } pub fn local(&self) -> &L { &self.local }
@ -58,9 +57,9 @@ where
pub async fn sync(&mut self) -> Result<(), Box<dyn Error>> { pub async fn sync(&mut self) -> Result<(), Box<dyn Error>> {
log::info!("Starting a sync."); log::info!("Starting a sync.");
let cals_server = self.server.get_calendars().await?; let cals_remote = self.remote.get_calendars().await?;
for (id, cal_server) in cals_server { for (id, cal_remote) in cals_remote {
let mut cal_server = cal_server.lock().unwrap(); let mut cal_remote = cal_remote.lock().unwrap();
let cal_local = match self.local.get_calendar(&id).await { let cal_local = match self.local.get_calendar(&id).await {
None => { None => {

View file

@ -24,14 +24,14 @@ async fn test_regular_sync() {
provider.sync().await.unwrap(); provider.sync().await.unwrap();
let cals_server = provider.server().get_calendars().await.unwrap(); let cals_server = provider.remote().get_calendars().await.unwrap();
println!("----Server-------"); println!("----Server-------");
my_tasks::utils::print_calendar_list(&cals_server).await; my_tasks::utils::print_calendar_list(&cals_server).await;
let cals_local = provider.local().get_calendars().await.unwrap(); let cals_local = provider.local().get_calendars().await.unwrap();
println!("\n----Local-------"); println!("\n----Local-------");
my_tasks::utils::print_calendar_list(&cals_local).await; my_tasks::utils::print_calendar_list(&cals_local).await;
assert!(provider.server().has_same_contents_than(provider.local()).await.unwrap()); assert!(provider.remote().has_same_contents_than(provider.local()).await.unwrap());
} }