From b5aacb58968189ed9358f3c71637c143fcf433ac Mon Sep 17 00:00:00 2001 From: Riley Apeldoorn Date: Tue, 16 Apr 2024 20:57:07 +0200 Subject: [PATCH] Project skeleton --- .gitignore | 1 + Cargo.toml | 8 +++ README.md | 3 ++ bin/pupctl/Cargo.toml | 8 +++ bin/pupctl/src/main.rs | 3 ++ bin/server/Cargo.toml | 8 +++ bin/server/src/main.rs | 8 +++ flake.lock | 95 ++++++++++++++++++++++++++++++++++++ flake.nix | 21 ++++++++ lib/fetch/Cargo.toml | 11 +++++ lib/fetch/src/lib.rs | 0 lib/puppy/Cargo.toml | 10 ++++ lib/puppy/src/lib.rs | 1 + lib/store/Cargo.toml | 9 ++++ lib/store/src/key.rs | 27 ++++++++++ lib/store/src/lib.rs | 24 +++++++++ lib/store/src/transaction.rs | 69 ++++++++++++++++++++++++++ rustfmt.toml | 4 ++ 18 files changed, 310 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 bin/pupctl/Cargo.toml create mode 100644 bin/pupctl/src/main.rs create mode 100644 bin/server/Cargo.toml create mode 100644 bin/server/src/main.rs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 lib/fetch/Cargo.toml create mode 100644 lib/fetch/src/lib.rs create mode 100644 lib/puppy/Cargo.toml create mode 100644 lib/puppy/src/lib.rs create mode 100644 lib/store/Cargo.toml create mode 100644 lib/store/src/key.rs create mode 100644 lib/store/src/lib.rs create mode 100644 lib/store/src/transaction.rs create mode 100644 rustfmt.toml 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.toml b/Cargo.toml new file mode 100644 index 0000000..e9d395b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +members = [ + "lib/puppy", + "lib/store", + "lib/fetch", + "bin/server", + "bin/pupctl", +] diff --git a/README.md b/README.md new file mode 100644 index 0000000..e491702 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# ActivityPuppy + +✨ Puppy, fetch my posts! diff --git a/bin/pupctl/Cargo.toml b/bin/pupctl/Cargo.toml new file mode 100644 index 0000000..9819730 --- /dev/null +++ b/bin/pupctl/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "pupctl" +edition = "2021" + +[dependencies] +puppy = { path = "../../lib/puppy" } +clap = { version = "*", features = ["derive"] } +cli-table = "*" diff --git a/bin/pupctl/src/main.rs b/bin/pupctl/src/main.rs new file mode 100644 index 0000000..2284bc4 --- /dev/null +++ b/bin/pupctl/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("pupctl") +} diff --git a/bin/server/Cargo.toml b/bin/server/Cargo.toml new file mode 100644 index 0000000..89fdc95 --- /dev/null +++ b/bin/server/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "server" +edition = "2021" + +[dependencies] +puppy = { path = "../../lib/puppy" } +tokio = { version = "*", features = ["full"] } +axum = "*" diff --git a/bin/server/src/main.rs b/bin/server/src/main.rs new file mode 100644 index 0000000..1737e4e --- /dev/null +++ b/bin/server/src/main.rs @@ -0,0 +1,8 @@ +use axum::{routing::get, Router}; + +#[tokio::main] +async fn main() { + let app = Router::new().route("/", get(|| async { "Hello, World!" })); + let sock = tokio::net::TcpListener::bind("0.0.0.0:1312").await.unwrap(); + axum::serve(sock, app).await.unwrap(); +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9351558 --- /dev/null +++ b/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710765496, + "narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1706487304, + "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "90f456026d284c22b3e3497be980b2e47d0b28ac", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "oxalica": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1710727870, + "narHash": "sha256-Ulsx+t4SnRmjMJx4eF2Li+3rBGYhZp0XNShVjIheCfg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a1b17cacfa7a6ed18f553a195a047f4e73e95da9", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "oxalica": "oxalica" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8c5f6b5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,21 @@ +{ + inputs = { + nixpkgs.url = github:NixOS/nixpkgs; + oxalica.url = github:oxalica/rust-overlay; + }; + + outputs = { nixpkgs, oxalica, ... }: let + pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [(import oxalica)]; }; + in{ + devShell."x86_64-linux" = pkgs.mkShell { + buildInputs = with pkgs; [ + (rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override { + extensions = [ "rust-src" "rustfmt" "rust-analyzer" ]; + })) + openssl + pkg-config + evcxr + ]; + }; + }; +} diff --git a/lib/fetch/Cargo.toml b/lib/fetch/Cargo.toml new file mode 100644 index 0000000..8211b67 --- /dev/null +++ b/lib/fetch/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "fetch" +edition = "2021" + +[lib] +path = "src/lib.rs" + +[dependencies] +reqwest = "*" +sigh = "*" +serde_json = "*" diff --git a/lib/fetch/src/lib.rs b/lib/fetch/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/lib/puppy/Cargo.toml b/lib/puppy/Cargo.toml new file mode 100644 index 0000000..613c157 --- /dev/null +++ b/lib/puppy/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "puppy" +edition = "2021" + +[lib] +path = "src/lib.rs" + +[dependencies] +store = { path = "../store" } +fetch = { path = "../fetch" } diff --git a/lib/puppy/src/lib.rs b/lib/puppy/src/lib.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/lib/puppy/src/lib.rs @@ -0,0 +1 @@ + diff --git a/lib/store/Cargo.toml b/lib/store/Cargo.toml new file mode 100644 index 0000000..d015c0b --- /dev/null +++ b/lib/store/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "store" +edition = "2021" + +[lib] +path = "src/lib.rs" + +[dependencies] +ulid = "*" diff --git a/lib/store/src/key.rs b/lib/store/src/key.rs new file mode 100644 index 0000000..debd525 --- /dev/null +++ b/lib/store/src/key.rs @@ -0,0 +1,27 @@ +pub const NODE: usize = 16; +pub const EDGE: usize = NODE * 2; + +#[derive(Clone, Copy)] +pub struct Key([u8; SIZE]); + +impl AsRef<[u8]> for Key { + fn as_ref(&self) -> &[u8] { + self.0.as_ref() + } +} + +impl Key { + pub fn join(self, other: Key) -> Key { + unsafe { std::mem::transmute((self, other)) } + } +} + +impl Key { + pub fn split(self) -> (Key, Key) { + unsafe { std::mem::transmute_copy(&self.0) } + } + pub fn swap(self) -> Key { + let (l, r) = self.split(); + r.join(l) + } +} diff --git a/lib/store/src/lib.rs b/lib/store/src/lib.rs new file mode 100644 index 0000000..9bc3ba2 --- /dev/null +++ b/lib/store/src/lib.rs @@ -0,0 +1,24 @@ +pub struct Store {} + +pub use key::Key; + +mod key; + +pub mod transaction; + +/// An (optionally labeled) directed edge between two keys. +pub trait Arrow { + /// Additional data associated with this edge. + type Label; +} + +/// A simple value associated with a key. +pub trait Value {} + +/// Aliases are unique mappings/indices that can be used in place of a key. +/// +/// They typically take the form of a newtype to add semantic meaning. +pub trait Alias {} + +/// Results from this component. +type Result = std::result::Result; diff --git a/lib/store/src/transaction.rs b/lib/store/src/transaction.rs new file mode 100644 index 0000000..c21c464 --- /dev/null +++ b/lib/store/src/transaction.rs @@ -0,0 +1,69 @@ +use crate::{Alias, Arrow, Key, Result, Value}; + +pub struct Transaction; + +/// Operations on [values][Value]. +impl Transaction { + pub fn lookup_value(&self, key: Key) -> Result<(Key, V)> + where + V: Value, + { + todo!() + } + pub fn insert_value(&self, key: Key) -> Result<()> + where + V: Value, + { + todo!() + } + pub fn update_value(&self, key: Key) -> Result<()> + where + V: Value, + { + todo!() + } + pub fn delete_value(&self, key: Key) -> Result<()> + where + V: Value, + { + todo!() + } +} + +/// Operations on [arrows][Arrow]. +impl Transaction { + pub fn create_arrow(&self, key: (Key, Key), label: A::Label) -> Result<()> + where + A: Arrow, + { + todo!() + } + pub fn delete_arrow(&self, key: (Key, Key)) -> Result<()> + where + A: Arrow, + { + todo!() + } + pub fn arrow_exists(&self, key: (Key, Key)) -> Result + where + A: Arrow, + { + todo!() + } +} + +/// Operations on [aliases][Alias]. +impl Transaction { + pub fn create_alias(&self, key: Key, alias: A) -> Result<()> + where + A: Alias, + { + todo!() + } + pub fn delete_alias(&self, alias: A) + where + A: Alias, + { + todo!() + } +} diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..9c177f5 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,4 @@ +unstable_features = true +overflow_delimited_expr = true +group_imports = "StdExternalCrate" +use_field_init_shorthand = true