Ware

Immutable middleware chains.

Ware allows you to create middleware chains that pass through and modify a value as they go along. You can imagine a middleware chain as something like this:

``` rust let initial_value = 1;

fn middleware_1(value: i32) -> i32 { value + 1 }

fn middleware_2(value: i32) -> i32 { value * 5 }

let result = middleware2(middleware1(initialvalue)); asserteq!(result, 10); ```

Ware abstracts over this concept like such:

``` rust use ware::Ware;

let mut middleware_chain: Ware = Ware::new();

middlewarechain.wrap(Box::new(|num| num + 1)); middlewarechain.wrap(Box::new(|num| num * 5));

let result = middlewarechain.run(1); asserteq!(result, 10); ```

Ware provides a single-argument struct (e.g. Ware<i32>) and a dual-argument struct (e.g. Ware2<i32, String>).

Functions that get registered as middleware cannot directly modify their variables, as they have to by of the Fn trait. I would recommend using immutable data structures that are efficient when duplicating values.

Documentation

The documentation is available at https://docs.rs/ware.

License

Ware is licensed under the Prosperity Public License (see LICENSE). You cannot use it commercially without my permission.