From b4b9515fd969cb6445c8a93b7eb1ec8ebe529949 Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Thu, 20 Aug 2020 21:41:45 +0200 Subject: rif: adding Recipes and Metadata --- Cargo.lock | 20 ++++++++++++++++++++ rif/Cargo.toml | 3 +++ rif/src/lib.rs | 11 ++++++++--- rif/src/recipe.rs | 18 ++++++++++++++++++ rif/src/schema.rs | 24 ++++++++++++++++++++---- rif/src/thread.rs | 1 + 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 rif/src/recipe.rs create mode 100644 rif/src/thread.rs diff --git a/Cargo.lock b/Cargo.lock index a397091..ad7cfa6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -246,6 +246,12 @@ dependencies = [ "autocfg", ] +[[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" @@ -365,9 +371,23 @@ dependencies = [ "proc-macro2", ] +[[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 "] 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 +where + I: Ingredient, + W: Workstep, +{ + schema: Schema, + metadata: Metadata, + threads: BTreeSet, +} + +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, - worksteps: BTreeSet, +pub struct Schema +where + I: Ingredient, + W: Workstep, +{ + /// Set of ingredients present in a recipe + pub ingredients: BTreeSet, + /// Set of allowed work-steps in a recipe + pub worksteps: BTreeSet, } /// 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 {} -- cgit v1.2.3