From a277f3fd9dd94e5b6929b2a57b2a3e0d703bd623 Mon Sep 17 00:00:00 2001 From: Avril Date: Wed, 6 Jan 2021 17:38:03 +0000 Subject: [PATCH] state: start --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 1 + src/state/body.rs | 33 +++++++++++++++++++++++++++++++++ src/state/mod.rs | 5 +++++ src/state/post.rs | 28 ++++++++++++++++++++++++++++ src/state/user.rs | 7 +++++++ 7 files changed, 76 insertions(+) create mode 100644 src/state/body.rs create mode 100644 src/state/mod.rs create mode 100644 src/state/post.rs create mode 100644 src/state/user.rs diff --git a/Cargo.lock b/Cargo.lock index 3c2b35a..b400517 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1401,6 +1401,7 @@ version = "0.1.0" dependencies = [ "difference", "futures", + "once_cell", "serde", "smallvec", "tokio", diff --git a/Cargo.toml b/Cargo.toml index e2149e3..1d63cc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ nightly = ["smallvec/const_generics"] [dependencies] difference = "2.0.0" futures = "0.3.8" +once_cell = "1.5.2" serde = {version = "1.0.118", features=["derive"]} smallvec = {version = "1.6.0", features= ["union", "serde", "write"]} tokio = {version = "0.2", features=["full"] } diff --git a/src/main.rs b/src/main.rs index 4d5b736..567ae0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ #[macro_use] mod ext; use ext::*; mod delta; +mod state; #[tokio::main] async fn main() { diff --git a/src/state/body.rs b/src/state/body.rs new file mode 100644 index 0000000..9f4051e --- /dev/null +++ b/src/state/body.rs @@ -0,0 +1,33 @@ +//! Open post body +use super::*; +use tokio::{ + sync::{ + watch, + mpsc, + }, +}; +use once_cell::sync::OnceCell; + +/// An open post body +#[derive(Debug)] +pub struct Karada +{ + scape: Vec, + + body_cache: String, + //TODO: Pub/sub? Or should that be in some other place? Probably. +} + +impl Karada +{ + fn invalidate_cache(&mut self) + { + self.body_cache = self.scape.iter().copied().collect(); + } + /// Apply this delta to the body. + pub fn apply_delta(&mut self, delta: &delta::Delta) + { + delta.insert(&mut self.scape); + self.invalidate_cache(); + } +} diff --git a/src/state/mod.rs b/src/state/mod.rs new file mode 100644 index 0000000..6e94012 --- /dev/null +++ b/src/state/mod.rs @@ -0,0 +1,5 @@ +use super::*; + +pub mod user; +pub mod post; +pub mod body; diff --git a/src/state/post.rs b/src/state/post.rs new file mode 100644 index 0000000..70122a0 --- /dev/null +++ b/src/state/post.rs @@ -0,0 +1,28 @@ +use super::*; + +#[derive(Debug)] +pub struct OpenPost +{ + +} + +#[derive(Debug)] +pub struct ClosedPost +{ + +} + +#[derive(Debug)] +pub enum PostKind +{ + Open(OpenPost), + Closed(ClosedPost), +} + +/// A post +#[derive(Debug)] +pub struct Post +{ + owner: user::UserID, + kind: PostKind +} diff --git a/src/state/user.rs b/src/state/user.rs new file mode 100644 index 0000000..eb20ee8 --- /dev/null +++ b/src/state/user.rs @@ -0,0 +1,7 @@ +//! Used to determine which post belongs to who. +//! +//! Mostly for determining if a poster owns a post. +use super::*; + +#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)] +pub struct UserID(()); //TODO: User ID. Maybe use IP + session ID hash?