From c46222c8c7027cf29481864acfcdc12c6aefeb19 Mon Sep 17 00:00:00 2001 From: daladim Date: Mon, 22 Mar 2021 22:39:50 +0100 Subject: [PATCH] [provider] Renamed server -> remote --- src/provider.rs | 29 ++++++++++++++--------------- tests/sync.rs | 4 ++-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/provider.rs b/src/provider.rs index 2b5c9b6..e424f00 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -11,17 +11,16 @@ use crate::traits::PartialCalendar; use crate::Item; 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. -pub struct Provider +pub struct Provider where L: CalDavSource, T: CompleteCalendar, - S: CalDavSource, + R: CalDavSource, U: PartialCalendar + Sync + Send, { - /// The remote server - server: S, + /// The remote source (usually a server) + remote: R, /// The local cache local: L, @@ -29,25 +28,25 @@ where phantom_u: PhantomData, } -impl Provider +impl Provider where L: CalDavSource, T: CompleteCalendar, - S: CalDavSource, + R: CalDavSource, U: PartialCalendar + Sync + Send, { /// Create a provider. /// - /// `server` 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 - pub fn new(server: S, local: L) -> Self { - Self { server, local, + /// `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 `remote` always wins in case of a sync conflict + pub fn new(remote: R, local: L) -> Self { + Self { remote, local, phantom_t: PhantomData, phantom_u: PhantomData, } } /// 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` pub fn local(&self) -> &L { &self.local } @@ -58,9 +57,9 @@ where pub async fn sync(&mut self) -> Result<(), Box> { log::info!("Starting a sync."); - let cals_server = self.server.get_calendars().await?; - for (id, cal_server) in cals_server { - let mut cal_server = cal_server.lock().unwrap(); + let cals_remote = self.remote.get_calendars().await?; + for (id, cal_remote) in cals_remote { + let mut cal_remote = cal_remote.lock().unwrap(); let cal_local = match self.local.get_calendar(&id).await { None => { diff --git a/tests/sync.rs b/tests/sync.rs index 6e0601f..b731ed6 100644 --- a/tests/sync.rs +++ b/tests/sync.rs @@ -24,14 +24,14 @@ async fn test_regular_sync() { provider.sync().await.unwrap(); - let cals_server = provider.server().get_calendars().await.unwrap(); + let cals_server = provider.remote().get_calendars().await.unwrap(); println!("----Server-------"); my_tasks::utils::print_calendar_list(&cals_server).await; let cals_local = provider.local().get_calendars().await.unwrap(); println!("\n----Local-------"); 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()); }