aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2020-08-23 14:46:27 +0200
committerKatharina Fey <kookie@spacekookie.de>2020-08-23 14:46:27 +0200
commit4d389ad4e6223ba56ec739fca55ad2e170a06a2b (patch)
treec4c2a90cb3a52cd7822706ddeb1d2be8620c44db
parent9f00deb9fcb35f43c2511a0ea562eed33271c723 (diff)
Adding ingredient/combine separationHEADdevelop
-rw-r--r--Cargo.toml2
-rw-r--r--rif/README.md20
-rw-r--r--rif/src/lib.rs4
-rw-r--r--rif/src/recipe.rs19
-rw-r--r--rif/src/schema.rs49
-rw-r--r--rif/src/thread.rs42
6 files changed, 101 insertions, 35 deletions
diff --git a/Cargo.toml b/Cargo.toml
index a6253e7..e756beb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,7 @@
[workspace]
members = [
+ # Utility libraries
"rif",
+
"cookbook-render",
] \ No newline at end of file
diff --git a/rif/README.md b/rif/README.md
new file mode 100644
index 0000000..e99b4c1
--- /dev/null
+++ b/rif/README.md
@@ -0,0 +1,20 @@
+# recipe instruction format (`rif`)
+
+A strongly typed expression format for recipes.
+
+Recipes consist of a schema which specifies available ingredients and
+worksteps, some metadata that is largely computed from the actual
+recipe, but can be queried from the main object, as well as a directed
+graph of ingredient measures and worksteps separated into threads.
+
+A thread is a set of instructions that can be executed by a single
+actor. Each thread has a set of inputs (ingredients) and an output,
+which is it's own type, a mix of ingredients created by the thread.
+
+
+## How to use
+
+```rust
+let schema = Schema::load("./main.rifs")?;
+let recp = Recipe::
+```
diff --git a/rif/src/lib.rs b/rif/src/lib.rs
index 047dc24..a27d90b 100644
--- a/rif/src/lib.rs
+++ b/rif/src/lib.rs
@@ -25,5 +25,5 @@ mod schema;
mod thread;
pub use recipe::{Metadata, Recipe};
-pub use schema::{Ingredient, Schema, Workstep};
-pub use thread::Thread;
+pub use schema::{Ingredient, Material, Schema, Workstep};
+pub use thread::{IngredientLike, Instruction, Measure, Thread};
diff --git a/rif/src/recipe.rs b/rif/src/recipe.rs
index 21b7912..0e3b8fe 100644
--- a/rif/src/recipe.rs
+++ b/rif/src/recipe.rs
@@ -2,16 +2,23 @@ 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>,
+pub struct Recipe {
+ schema: Schema,
metadata: Metadata,
threads: BTreeSet<Thread>,
}
+impl Recipe {
+ /// Create a new recipe from a schema, with a name and version
+ pub fn new(schema: Schema, name: String, version: String) -> Self {
+ Self {
+ schema,
+ metadata: Metadata { name, version },
+ threads: Default::default(),
+ }
+ }
+}
+
pub struct Metadata {
pub name: String,
pub version: String,
diff --git a/rif/src/schema.rs b/rif/src/schema.rs
index 28c1304..ac3052e 100644
--- a/rif/src/schema.rs
+++ b/rif/src/schema.rs
@@ -2,37 +2,34 @@ use identity::Identity as Id;
use std::collections::BTreeSet;
/// A schema format backing a recipe set
-pub struct Schema<I, W>
-where
- I: Ingredient,
- W: Workstep,
-{
+#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
+pub struct Schema {
/// Set of ingredients present in a recipe
- pub ingredients: BTreeSet<I>,
+ pub ingredients: BTreeSet<Ingredient>,
/// Set of allowed work-steps in a recipe
- pub worksteps: BTreeSet<W>,
+ pub worksteps: BTreeSet<Workstep>,
}
-/// 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;
+#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
+pub struct Ingredient {
+ pub name: String,
+ pub slug: String,
+ pub id: 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;
- /// Execute some custom code for the step
- fn run(&self) -> Option<()>;
+#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
+pub struct Workstep {
+ pub id: Id,
+ pub name: String,
+ pub slug: String,
+ pub description: String,
+}
+
+/// A piece of gear required to execute an action
+pub struct Material {
+ pub id: Id,
+ pub name: String,
+ pub slug: String,
+ pub description: String,
}
diff --git a/rif/src/thread.rs b/rif/src/thread.rs
index c543850..5de9cd5 100644
--- a/rif/src/thread.rs
+++ b/rif/src/thread.rs
@@ -1 +1,41 @@
-pub struct Thread {}
+use crate::{Ingredient, Workstep};
+use std::collections::BTreeSet;
+
+#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
+pub struct Thread {
+ pub name: String,
+ pub instructions: Vec<Instruction>,
+ pub inputs: BTreeSet<Measure>,
+ pub outputs: BTreeSet<Measure>,
+}
+
+/// An ingredient with precise attached measurements
+#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
+pub struct Measure {
+ /// Base ingredient from the schema
+ pub ingredient: Ingredient,
+ /// Numerical amount
+ pub amount: usize,
+ /// Scale offset
+ pub scale: u64,
+}
+
+/// Differentiator between raw schema ingredient or work result
+pub enum IngredientLike {
+ /// An ingredient backed by the recipe schema
+ Raw(Ingredient),
+ /// An ingredient produced by a subset of the recipe
+ Combine(Combine),
+}
+
+/// A specific variation of a `Workstep` which acts on Measures
+#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
+pub struct Instruction {}
+
+/// The result of an instruction, which is not a base ingredient
+#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
+pub struct Combine {
+ inputs: BTreeSet<IngredientLike>,
+ name: String,
+ slug: String,
+}