[][src]Crate ware

Ware provides immutable middleware abstractions. Basically, it means that you can pass one variable through a series of functions that all have the ability to modify this variable, therefore sending this modified version of it further down the chain.

Ware is used like this:

use ware::Ware;

fn main() {
    let mut chain: Ware<i32> = Ware::new();
    chain.wrap(Box::new(|num| num * 10));
    chain.wrap(Box::new(|num| num - 2));
    let result = chain.run(5);
    assert_eq!(result, 48);
}

Ware also provides a version of itself that can pass through two variables at once, since Rust doesn't support variadic functions (functions that can have multiple numbers of arguments). In middleware functions for these, you return a 2-tuple instead of a single value:

use ware::Ware2;

fn main() {
    let mut chain: Ware2<i32, i32> = Ware2::new();
    chain.wrap(Box::new(|num1, num2| (num1 - 4, num2 + 3)));
    let (res1, res2) = chain.run(10, 10);
    assert_eq!(res1, 6);
    assert_eq!(res2, 13);
}

Structs

Ware

A middleware chain that can pass through one argument.

Ware2

A middleware chain that can pass through two arguments.