From 58b96a89b0a9189dadbe398f8045b8fc9148384f Mon Sep 17 00:00:00 2001 From: daladim Date: Thu, 18 Feb 2021 12:02:04 +0100 Subject: [PATCH] Initial API structre --- .gitignore | 1 + Cargo.lock | 14 +++++++++++ Cargo.toml | 10 ++++++++ src/bin/my-tasks.rs | 3 +++ src/data/calendar.rs | 24 +++++++++++++++++++ src/data/client.rs | 7 ++++++ src/data/mod.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++ src/data/tasks.rs | 18 +++++++++++++++ src/lib.rs | 1 + 9 files changed, 133 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/bin/my-tasks.rs create mode 100644 src/data/calendar.rs create mode 100644 src/data/client.rs create mode 100644 src/data/mod.rs create mode 100644 src/data/tasks.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6eb2da0 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,14 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "my-tasks" +version = "0.1.0" +dependencies = [ + "uuid", +] + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f4d9f3c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "my-tasks" +version = "0.1.0" +authors = ["Jérôme"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +uuid = "0.8" diff --git a/src/bin/my-tasks.rs b/src/bin/my-tasks.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/bin/my-tasks.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/data/calendar.rs b/src/data/calendar.rs new file mode 100644 index 0000000..94c2fa9 --- /dev/null +++ b/src/data/calendar.rs @@ -0,0 +1,24 @@ +use crate::data::TaskView; + +/// A Caldav Calendar +pub struct Calendar { + name: String, + + tasks: Vec, +} + +impl Calendar { + pub fn name() -> String { + self.name + } + + pub fn tasks() -> Vec { + self.tasks + } +} + +impl Drop for Calendar { + fn drop(&mut self) { + // TODO: display a warning in case some TaskViews still have a refcount > 0 + } +} diff --git a/src/data/client.rs b/src/data/client.rs new file mode 100644 index 0000000..89f5f86 --- /dev/null +++ b/src/data/client.rs @@ -0,0 +1,7 @@ +pub struct Client {} + +impl Client { + pub fn new(&mut self, url: String, username: String, password: String) -> Self { + Self{} + } +} \ No newline at end of file diff --git a/src/data/mod.rs b/src/data/mod.rs new file mode 100644 index 0000000..05eb0d8 --- /dev/null +++ b/src/data/mod.rs @@ -0,0 +1,55 @@ +//! 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 + +use std::sync::Arc; + +mod calendar; +mod tasks; +mod client; + +pub use calendar::Calendar; +pub use tasks::Task; +use client::Client; + +// TODO: consider using references here +// (there will be no issue with still-borrowed-data when the DataSource is destroyed, but will it play well with sync stuff?) +type CalendarView = Arc; +type TaskView = Arc; + +/// A Caldav data source +pub struct DataSource { + client: Option, + + calendars: Vec +} + +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) { + self.client = Client::new(url, username, password); + } + + /// Update the local database with info from the Client + pub fn fetch_from_server(&self) { + // TODO: how to handle conflicts? + } + + pub fn calendars(&self) -> Vec { + self.calendars + } +} + +impl Drop for DataSource { + fn drop(&mut self) { + // TODO: display a warning in case some CalendarViews still have a refcount > 0 + } +} diff --git a/src/data/tasks.rs b/src/data/tasks.rs new file mode 100644 index 0000000..838e9cb --- /dev/null +++ b/src/data/tasks.rs @@ -0,0 +1,18 @@ +use uuid::Uuid; + +/// A to-do task +pub struct Task { + id: Uuid, + name: String, +} + +impl Task { + pub fn id(&self) -> Uuid { self.id } + pub fn name(&self) -> String { self.name } + pub fn completed(&self) -> bool { self.completed } + + pub fn set_completed(&mut self) { + // TODO: either require a reference to the DataSource, so that it is aware + // or change a flag here, and the DataSource will be able to check the flags of all its content (but then the Calendar should only give a reference/Arc, not a clone) + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..7a345e4 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod data;