diff --git a/src/bin/my-tasks.rs b/src/bin/my-tasks.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/bin/my-tasks.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/src/cache.rs b/src/cache.rs new file mode 100644 index 0000000..1b134e9 --- /dev/null +++ b/src/cache.rs @@ -0,0 +1 @@ +//! This module provides a local cache for CalDAV data \ No newline at end of file diff --git a/src/data/calendar.rs b/src/calendar.rs similarity index 97% rename from src/data/calendar.rs rename to src/calendar.rs index 8f8ee60..e74aada 100644 --- a/src/data/calendar.rs +++ b/src/calendar.rs @@ -3,8 +3,8 @@ use std::error::Error; use url::Url; -use crate::data::Task; -use crate::data::task::TaskId; +use crate::task::Task; +use crate::task::TaskId; use bitflags::bitflags; diff --git a/src/data/client.rs b/src/client.rs similarity index 96% rename from src/data/client.rs rename to src/client.rs index 756b35c..36716ca 100644 --- a/src/data/client.rs +++ b/src/client.rs @@ -1,6 +1,4 @@ -//! Code to connect to a Caldav server -//! -//! Some of it comes from https://github.com/marshalshi/caldav-client-rust.git +//! This module provides a client to connect to a CalDAV server use std::error::Error; use std::convert::TryFrom; @@ -11,7 +9,7 @@ use minidom::Element; use url::Url; use crate::utils::{find_elem, find_elems}; -use crate::data::Calendar; +use crate::calendar::Calendar; static DAVCLIENT_BODY: &str = r#" @@ -200,7 +198,7 @@ impl Client { let mut this_calendar_url = self.url.clone(); this_calendar_url.set_path(&calendar_href); - let supported_components = match crate::data::calendar::SupportedComponents::try_from(el_supported_comps.clone()) { + let supported_components = match crate::calendar::SupportedComponents::try_from(el_supported_comps.clone()) { Err(err) => { log::warn!("Calendar {} has invalid supported components ({})! Ignoring it.", display_name, err); continue; diff --git a/src/lib.rs b/src/lib.rs index 4635634..0b0eb21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,21 @@ -pub mod data; +//! This crate provides a way to manage CalDAV data. +//! +//! It provides a CalDAV client in the [`client`] module, that can be used as a stand-alone module. +//! +//! Because the connection to the server may be slow, and a user-frendly app may want to quicky display cached data on startup, this crate also provides a local cache for CalDAV data in the [`cache`] module. +//! +//! These two "data sources" (actual client and local cache) can be used together in a [`Provider`](provider::Provider). \ +//! A `Provider` abstracts these two sources by merging them together into one virtual source. \ +//! It also handles synchronisation between the local cache and the server. + +mod calendar; +pub use calendar::Calendar; +mod task; +pub use task::Task; + +pub mod client; +pub mod provider; +pub mod cache; + pub mod settings; pub mod utils; diff --git a/src/provider.rs b/src/provider.rs new file mode 100644 index 0000000..926514d --- /dev/null +++ b/src/provider.rs @@ -0,0 +1,3 @@ +//! This modules abstracts data sources and merges them in a single virtual one + +pub struct Provider {} diff --git a/src/data/task.rs b/src/task.rs similarity index 100% rename from src/data/task.rs rename to src/task.rs diff --git a/src/data/mod.rs b/src/traits.rs similarity index 69% rename from src/data/mod.rs rename to src/traits.rs index 3c8e08a..6d530ef 100644 --- a/src/data/mod.rs +++ b/src/traits.rs @@ -1,17 +1,9 @@ -//! This module is the data source of the Caldav items -//! -//! This gives access to data from both the server and a local database for quick retrieval when the app starts +//! This module provides CalDAV data sources and utilities -use std::sync::Arc; +/* use std::error::Error; -pub mod calendar; -mod task; -pub mod client; -pub use calendar::Calendar; -pub use task::Task; -use client::Client; /// A Caldav data source pub struct DataSource { @@ -37,16 +29,21 @@ impl DataSource { /// Update the local database with info from the Client pub fn fetch_from_server(&mut self) { - + // TODO: how to handle conflicts? } pub fn update_changes_to_server(&self) { } + // TODO: the API should force calling fetch_from_server before pub fn calendars(&self) -> Vec<&Calendar> { + // TODO: what happens when a user has a reference, which is modified/updated from the server? Conflict mut/not mut? + // TODO: how can the user modify Tasks from a non-mut reference? self.calendars .iter() .collect() } } + +*/ diff --git a/tests/caldav_client.rs b/tests/caldav_client.rs index 2337666..25f04ec 100644 --- a/tests/caldav_client.rs +++ b/tests/caldav_client.rs @@ -9,7 +9,7 @@ use reqwest::header::CONTENT_TYPE; use minidom::Element; use url::Url; -use my_tasks::data::client::Client; +use my_tasks::client::Client; use my_tasks::settings::URL; use my_tasks::settings::USERNAME; use my_tasks::settings::PASSWORD;