From 78d800b461db9d3aa8142c85f282e3de0ca84d02 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Mon, 19 Feb 2024 18:09:10 +0100 Subject: [PATCH] prowocessing: extract experiment into its own file --- crates/prowocessing/src/experimental.rs | 1 + .../src/experimental/enum_based.rs | 64 +++++++++++++++++ crates/prowocessing/src/lib.rs | 69 +------------------ 3 files changed, 66 insertions(+), 68 deletions(-) create mode 100644 crates/prowocessing/src/experimental.rs create mode 100644 crates/prowocessing/src/experimental/enum_based.rs diff --git a/crates/prowocessing/src/experimental.rs b/crates/prowocessing/src/experimental.rs new file mode 100644 index 0000000..090198e --- /dev/null +++ b/crates/prowocessing/src/experimental.rs @@ -0,0 +1 @@ +pub mod enum_based; diff --git a/crates/prowocessing/src/experimental/enum_based.rs b/crates/prowocessing/src/experimental/enum_based.rs new file mode 100644 index 0000000..c60f4a9 --- /dev/null +++ b/crates/prowocessing/src/experimental/enum_based.rs @@ -0,0 +1,64 @@ +pub enum Instruction { + Uppercase, + Lowercase, +} + +pub struct Pipeline { + pipeline: Vec String>, +} + +impl Pipeline { + pub fn run(&self, val: String) -> String { + let mut current = val; + + for instr in &self.pipeline { + current = instr(current); + } + + current + } +} + +pub struct PipelineBuilder { + pipeline: Vec, +} + +impl PipelineBuilder { + pub fn new() -> Self { + Self { + pipeline: Vec::new(), + } + } + + #[must_use] + pub fn insert(mut self, instr: Instruction) -> Self { + self.pipeline.push(instr); + self + } + + pub fn build(&self) -> Pipeline { + fn uppercase(v: String) -> String { + str::to_uppercase(&v) + } + fn lowercase(v: String) -> String { + str::to_lowercase(&v) + } + + let mut res = Vec::new(); + + for item in &self.pipeline { + res.push(match item { + Instruction::Uppercase => uppercase, + Instruction::Lowercase => lowercase, + }); + } + + Pipeline { pipeline: res } + } +} + +impl Default for PipelineBuilder { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/prowocessing/src/lib.rs b/crates/prowocessing/src/lib.rs index 778d544..2e7b047 100644 --- a/crates/prowocessing/src/lib.rs +++ b/crates/prowocessing/src/lib.rs @@ -7,74 +7,7 @@ use experimental::enum_based::{Instruction, PipelineBuilder}; /// just some experiments, to test whether the architecture i want is even possible (or how to do it). probably temporary. /// Gonna first try string processing... -pub mod experimental { - pub mod enum_based { - pub enum Instruction { - Uppercase, - Lowercase, - } - - pub struct Pipeline { - pipeline: Vec String>, - } - - impl Pipeline { - pub fn run(&self, val: String) -> String { - let mut current = val; - - for instr in &self.pipeline { - current = instr(current); - } - - current - } - } - - pub struct PipelineBuilder { - pipeline: Vec, - } - - impl PipelineBuilder { - pub fn new() -> Self { - Self { - pipeline: Vec::new(), - } - } - - #[must_use] - pub fn insert(mut self, instr: Instruction) -> Self { - self.pipeline.push(instr); - self - } - - pub fn build(&self) -> Pipeline { - fn uppercase(v: String) -> String { - str::to_uppercase(&v) - } - fn lowercase(v: String) -> String { - str::to_lowercase(&v) - } - - let mut res = Vec::new(); - - for item in &self.pipeline { - res.push(match item { - Instruction::Uppercase => uppercase, - Instruction::Lowercase => lowercase, - }); - } - - Pipeline { pipeline: res } - } - } - - impl Default for PipelineBuilder { - fn default() -> Self { - Self::new() - } - } - } -} +pub mod experimental; #[test] fn test_enums() {