Browse Source

Refactored modules

github_actions
daladim 5 years ago
parent
commit
7e3bccb5ad
  1. 3
      src/bin/my-tasks.rs
  2. 1
      src/cache.rs
  3. 4
      src/calendar.rs
  4. 8
      src/client.rs
  5. 20
      src/lib.rs
  6. 3
      src/provider.rs
  7. 0
      src/task.rs
  8. 19
      src/traits.rs
  9. 2
      tests/caldav_client.rs

3
src/bin/my-tasks.rs

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

1
src/cache.rs

@ -0,0 +1 @@
//! This module provides a local cache for CalDAV data

4
src/data/calendar.rs → 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;

8
src/data/client.rs → 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#"
<d:propfind xmlns:d="DAV:">
@ -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;

20
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;

3
src/provider.rs

@ -0,0 +1,3 @@
//! This modules abstracts data sources and merges them in a single virtual one
pub struct Provider {}

0
src/data/task.rs → src/task.rs

19
src/data/mod.rs → 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()
}
}
*/

2
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;

Loading…
Cancel
Save