aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2020-08-20 21:41:45 +0200
committerKatharina Fey <kookie@spacekookie.de>2020-08-20 21:41:45 +0200
commitb4b9515fd969cb6445c8a93b7eb1ec8ebe529949 (patch)
treecacb2255f9dfba2f72738ffeab28e820f0422090
parentf76b3008a69e376fac06a1c383936531748e654a (diff)
rif: adding Recipes and Metadata
-rw-r--r--Cargo.lock20
-rw-r--r--rif/Cargo.toml3
-rw-r--r--rif/src/lib.rs11
-rw-r--r--rif/src/recipe.rs18
-rw-r--r--rif/src/schema.rs24
-rw-r--r--rif/src/thread.rs1
6 files changed, 70 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a397091..ad7cfa6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -247,6 +247,12 @@ dependencies = [
]
[[package]]
+name = "hex"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
+
+[[package]]
name = "http"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -366,8 +372,22 @@ dependencies = [
]
[[package]]
+name = "ratman-identity"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3e94cc012804fd49daa7e0eecb6e3831f58b517dd0152c9533912c09bc5b8972"
+dependencies = [
+ "cfg-if",
+ "hex",
+ "serde",
+]
+
+[[package]]
name = "rif"
version = "0.1.0"
+dependencies = [
+ "ratman-identity",
+]
[[package]]
name = "ryu"
diff --git a/rif/Cargo.toml b/rif/Cargo.toml
index 448ce3b..1f02bd6 100644
--- a/rif/Cargo.toml
+++ b/rif/Cargo.toml
@@ -3,3 +3,6 @@ name = "rif"
version = "0.1.0"
authors = ["Kaiden Fey <kookie@spacekookie.de>"]
edition = "2018"
+
+[dependencies]
+identity = { version = "0.4", package = "ratman-identity" } \ No newline at end of file
diff --git a/rif/src/lib.rs b/rif/src/lib.rs
index 0e18044..047dc24 100644
--- a/rif/src/lib.rs
+++ b/rif/src/lib.rs
@@ -3,7 +3,7 @@
//! A structured format for expression recipes, and work steps with
//! variable actor counts. Ingredients and work steps are typed via
//! an internally provided schema. The backing file-format for
-//! serialisation is `g3f`.
+//! serialisation is [`g3f`](https://github.com/spacekookie/g3f).
//!
//! Each recipe is separated into threads, with a set of inputs, work
//! steps and an output. A thread is a set of work steps that can be
@@ -17,8 +17,13 @@
//! ```rust
//! let mut r = Recipe::new();
//! let mut t = r.add_thread().name("a");
-//!
+//!
//! ```
-
+mod recipe;
mod schema;
+mod thread;
+
+pub use recipe::{Metadata, Recipe};
+pub use schema::{Ingredient, Schema, Workstep};
+pub use thread::Thread;
diff --git a/rif/src/recipe.rs b/rif/src/recipe.rs
new file mode 100644
index 0000000..21b7912
--- /dev/null
+++ b/rif/src/recipe.rs
@@ -0,0 +1,18 @@
+use crate::{Ingredient, Schema, Thread, Workstep};
+use std::collections::BTreeSet;
+
+/// A recipe with instructions to execute
+pub struct Recipe<I, W>
+where
+ I: Ingredient,
+ W: Workstep,
+{
+ schema: Schema<I, W>,
+ metadata: Metadata,
+ threads: BTreeSet<Thread>,
+}
+
+pub struct Metadata {
+ pub name: String,
+ pub version: String,
+}
diff --git a/rif/src/schema.rs b/rif/src/schema.rs
index df7b6b4..28c1304 100644
--- a/rif/src/schema.rs
+++ b/rif/src/schema.rs
@@ -1,22 +1,38 @@
use identity::Identity as Id;
+use std::collections::BTreeSet;
/// A schema format backing a recipe set
-pub struct Schema {
- ingredients: BTreeSet<Ingredient>,
- worksteps: BTreeSet<Workstep>,
+pub struct Schema<I, W>
+where
+ I: Ingredient,
+ W: Workstep,
+{
+ /// Set of ingredients present in a recipe
+ pub ingredients: BTreeSet<I>,
+ /// Set of allowed work-steps in a recipe
+ pub worksteps: BTreeSet<W>,
}
/// A string-tagged ingredient in a recipe
pub trait Ingredient {
+ /// Get a human readable ingredient name
fn name(&self) -> String;
+ /// Get the ingredient slug
fn slug(&self) -> String;
+ /// A machine-efficient, random ID
fn id(&self) -> Id;
}
/// An execution step
pub trait Workstep {
+ /// Get a human readable workstep name
fn name(&self) -> String;
+ /// Get the workstep slug
+ fn slug(&self) -> String;
+ /// Get the human readable workstep description
fn description(&self) -> String;
+ /// A machine-efficient, random ID
fn id(&self) -> Id;
- async fn run(&self) -> Option<()>;
+ /// Execute some custom code for the step
+ fn run(&self) -> Option<()>;
}
diff --git a/rif/src/thread.rs b/rif/src/thread.rs
new file mode 100644
index 0000000..c543850
--- /dev/null
+++ b/rif/src/thread.rs
@@ -0,0 +1 @@
+pub struct Thread {}