function-compose

Crate function-compose provides utilities for composing functions and way to inject arguments to functions
Composing functions
step 1
Mark a function as composeable as below. Note that the functions must always return Result type
use composeable;
step 2
use compose! macro to compose the above two functions.
let result = compose!;
assert_eq!;
Argument 10(from with_args(10)). is passed to add_10 function and result of add_10 is passed to add_100
composing Async functions
It is also possible to compose sync and asycn function.
For async function, return type should be BoxedFuture(futures crate)
use composeable;
use ;
Composing async and sync functions usage
use compose;
use composeable;
use ;
async
Injecting dependencies in multi-args function
For function with multiple arguments(say 2), One of the argument can be injected during composition itself.
Function argument injection usage
use composeable;
use ;
use cratecompose;
let result = compose!.await;
assert_eq!;
In the above example function add_3_arg_async, out of three arguments, 2 are injected during composing the function itself (using provide(100)) . This feature could be used for injecting connection pool or a repository instance(see the example project).
Retry in Fn Composer
Composeable macro supports retrying a function at specified interval in case of Error returned by the function. This could be useful when trying make a database call or connect to network endpoint. Make sure to add https://docs.rs/retry/latest/retry/ to your project before proceeding with retry feature.
Retry mechanism is implemented as part of composeable procedureal macro. Below is example of add_10 function configured to be retried 2 times after initial failure.
use *;
Retry can be applied to both sync and async functions.
for async functions, all arguments to the function must be either shared reference or exclusive reference.
Below is example of async function with retry.
Apart from fixed duration retries, it is possible to configure with exponential delay. Refer to retry documentation for all available delay options https://docs.rs/retry/latest/retry/all.html