enum_pipeline 2.0.0

Provides a way to use enums to describe and execute ordered data pipelines.
Documentation
  • Coverage
  • 85.71%
    6 out of 7 items documented0 out of 6 items with examples
  • Size
  • Source code size: 21.57 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.29 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • benferse bengreenier

enum-pipeline

Provides a way to use enums to describe and execute ordered data pipelines. 🦀🐾

CI Crates.io docs.rs dependency status

I needed a succinct way to describe 2d pixel map operations for a game I'm working on. I wanted callers to be able to easily determine all possible operations (hence enum), with per-operation data (hence variants), and their operation-specific logic. This is what I came up with!

Quickstart

Some quick examples to get you started. For more information see docs.rs/enum_pipeline and docs.rs/enum_pipeline_derive.

Derive

#[derive(Default)]
struct MacroMutRefData {
    a_count: i32,
    b_count: i32,
}

#[derive(ExecuteWithMut)]
#[execute_with(MacroMutRefData)]
enum MacroMutRefPipeline {
    #[handler(handle_a)]
    A(i32),
    #[handler(handle_b)]
    B,
}

impl MacroMutRefPipeline {
    fn handle_a(i: i32, arg: &mut MacroMutRefData) {
        arg.a_count += 1;
    }

    fn handle_b(arg: &mut MacroMutRefData) {
        arg.b_count += 1;
    }
}

Then create and execute some pipelines:

let mut arg = MacroMutRefData::default();
vec![MacroMutRefPipeline::A(23), MacroMutRefPipeline::B].execute_with_mut(&mut arg);

Manual

#[derive(Default)]
struct MutRefData {
    a_count: i32,
    b_count: i32,
}

enum MutRefPipeline {
    A(i32),
    B,
}

impl ExecuteWithMut<MutRefData> for MutRefPipeline {
    fn execute_with_mut(self, arg: &mut MutRefData) {
        match self {
            MutRefPipeline::A(i) => arg.a_count += 1,
            MutRefPipeline::B => arg.b_count += 1,
        }
    }
}

Then create and execute some pipelines:

let mut arg = MutRefData::default();
vec![MutRefPipeline::A(23), MutRefPipeline::B].execute_with_mut(&mut arg);

License

MIT