Added the CalDavSource trait

This commit is contained in:
daladim 2021-02-25 00:47:39 +01:00
parent 364c91fed2
commit cefcb7289f
3 changed files with 13 additions and 43 deletions

View file

@ -16,3 +16,4 @@ url = { version = "2.2", features = ["serde"] }
bitflags = "1.2" bitflags = "1.2"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
async-trait = "0.1"

View file

@ -8,6 +8,8 @@
//! A `Provider` abstracts these two sources by merging them together into one virtual source. \ //! 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. //! It also handles synchronisation between the local cache and the server.
pub mod traits;
pub mod calendar; pub mod calendar;
pub use calendar::Calendar; pub use calendar::Calendar;
mod task; mod task;

View file

@ -1,49 +1,16 @@
//! This module provides CalDAV data sources and utilities
/*
use std::error::Error; use std::error::Error;
use async_trait::async_trait;
use crate::Calendar;
/// A Caldav data source #[async_trait]
pub struct DataSource { pub trait CalDavSource {
client: Option<Client>, /// 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)
async fn get_calendars(&self) -> Result<&Vec<Calendar>, Box<dyn Error>>;
calendars: Vec<Calendar> /// 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)
async fn get_calendars_mut(&mut self) -> Result<Vec<&mut Calendar>, Box<dyn Error>>;
} }
impl DataSource {
/// Create a new data source
pub fn new() -> Self {
Self{
client: None,
calendars: Vec::new(),
}
}
/// Tell this data source what the source server is
pub fn set_server(&mut self, url: String, username: String, password: String) -> Result<(), Box<dyn Error>> {
self.client = Some(Client::new(url, username, password)?);
Ok(())
}
/// 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()
}
}
*/