Project skeleton

This commit is contained in:
Riley Apeldoorn 2024-04-16 20:57:07 +02:00
commit b5aacb5896
18 changed files with 310 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[workspace]
members = [
"lib/puppy",
"lib/store",
"lib/fetch",
"bin/server",
"bin/pupctl",
]

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# ActivityPuppy
✨ Puppy, fetch my posts!

8
bin/pupctl/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "pupctl"
edition = "2021"
[dependencies]
puppy = { path = "../../lib/puppy" }
clap = { version = "*", features = ["derive"] }
cli-table = "*"

3
bin/pupctl/src/main.rs Normal file
View File

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

8
bin/server/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "server"
edition = "2021"
[dependencies]
puppy = { path = "../../lib/puppy" }
tokio = { version = "*", features = ["full"] }
axum = "*"

8
bin/server/src/main.rs Normal file
View File

@ -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();
}

95
flake.lock Normal file
View File

@ -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
}

21
flake.nix Normal file
View File

@ -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
];
};
};
}

11
lib/fetch/Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "fetch"
edition = "2021"
[lib]
path = "src/lib.rs"
[dependencies]
reqwest = "*"
sigh = "*"
serde_json = "*"

0
lib/fetch/src/lib.rs Normal file
View File

10
lib/puppy/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "puppy"
edition = "2021"
[lib]
path = "src/lib.rs"
[dependencies]
store = { path = "../store" }
fetch = { path = "../fetch" }

1
lib/puppy/src/lib.rs Normal file
View File

@ -0,0 +1 @@

9
lib/store/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "store"
edition = "2021"
[lib]
path = "src/lib.rs"
[dependencies]
ulid = "*"

27
lib/store/src/key.rs Normal file
View File

@ -0,0 +1,27 @@
pub const NODE: usize = 16;
pub const EDGE: usize = NODE * 2;
#[derive(Clone, Copy)]
pub struct Key<const SIZE: usize = NODE>([u8; SIZE]);
impl<const S: usize> AsRef<[u8]> for Key<S> {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl Key {
pub fn join(self, other: Key) -> Key<EDGE> {
unsafe { std::mem::transmute((self, other)) }
}
}
impl Key<EDGE> {
pub fn split(self) -> (Key, Key) {
unsafe { std::mem::transmute_copy(&self.0) }
}
pub fn swap(self) -> Key<EDGE> {
let (l, r) = self.split();
r.join(l)
}
}

24
lib/store/src/lib.rs Normal file
View File

@ -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<T, E = ()> = std::result::Result<T, E>;

View File

@ -0,0 +1,69 @@
use crate::{Alias, Arrow, Key, Result, Value};
pub struct Transaction;
/// Operations on [values][Value].
impl Transaction {
pub fn lookup_value<V>(&self, key: Key) -> Result<(Key, V)>
where
V: Value,
{
todo!()
}
pub fn insert_value<V>(&self, key: Key) -> Result<()>
where
V: Value,
{
todo!()
}
pub fn update_value<V>(&self, key: Key) -> Result<()>
where
V: Value,
{
todo!()
}
pub fn delete_value<V>(&self, key: Key) -> Result<()>
where
V: Value,
{
todo!()
}
}
/// Operations on [arrows][Arrow].
impl Transaction {
pub fn create_arrow<A>(&self, key: (Key, Key), label: A::Label) -> Result<()>
where
A: Arrow,
{
todo!()
}
pub fn delete_arrow<A>(&self, key: (Key, Key)) -> Result<()>
where
A: Arrow,
{
todo!()
}
pub fn arrow_exists<A>(&self, key: (Key, Key)) -> Result<bool>
where
A: Arrow,
{
todo!()
}
}
/// Operations on [aliases][Alias].
impl Transaction {
pub fn create_alias<A>(&self, key: Key, alias: A) -> Result<()>
where
A: Alias,
{
todo!()
}
pub fn delete_alias<A>(&self, alias: A)
where
A: Alias,
{
todo!()
}
}

4
rustfmt.toml Normal file
View File

@ -0,0 +1,4 @@
unstable_features = true
overflow_delimited_expr = true
group_imports = "StdExternalCrate"
use_field_init_shorthand = true