pipa
Pipe Operator Library for Rust.
Features:
- Pipe things into chain of expressions.
- Support different types.
- Support pipe for functions, closures and methods returning
Try-able types(Option & Result). - Support pipe for async functions and async methods returning
Try-able types(Option & Result). - Support pipe for associated functions returning
Try-able types(Option & Result). - Support pipe for async associated functions returning
Try-able types(Option & Result). - Support pipe for methods calls returning
Try-able types(Option & Result). - Support pipe for async methods calls returning
Try-able types(Option & Result). - Support pipe for inline closures.
- Support Railway-Oriented Programming pattern with simple and terse syntax.
Example:
// call functions f taking 123 as its only parameter, and return as g's only parameter and g returns as h's only parameter, and so on.
// `fn f(n: i32) -> T`
// `fn g(n: T) -> U`
// `fn h(n: U) -> V`
// ret == V
let ret = pipa!;
// same as above, except all functions chained appended with `?` as they return Result/Option.
// the T of each Result<T, E> or Option<T> will be input argument for the next functions.
// `fn f(n: i32) -> Result<T, E>`
// `fn g(n: T) -> Result<U, E>`
// `fn h(n: U) -> Result<V, E>`
// ret == V
// Try operator automatically applied in each calls chain.
let ret = pipa_try!;
// same as both above, except functions are async, await-ed, and return Result/Option.
// `async fn f(n: i32) -> Result<T, E>`
// `async fn g(n: T) -> Result<U, E>`
// `async fn h(n: U) -> Result<V, E>`
// ret == V
// Each functions get await-ed and try operator automatically applied in each calls chain.
let ret = pipa_await_try!;
Example mixing multiple kinds of expressions:
let clo = ;
let result = p!;
let ret = p!;
assert_eq!;
let ret = p!;
assert_eq!;
// inline closure tests
let ret = p!;
assert_eq!;
dbg!;
let ret = p!;
assert_eq!;
dbg!;
let ret = p!;
assert_eq!;
dbg!;
let ret = p!;
assert_eq!;
dbg!;
let ret = p!;
assert_eq!;
dbg!;
let ret = p!;
assert_eq!;
dbg!;
let ret = p!;
assert_eq!;
dbg!;
More detail in tests/test.rs & tests/mixed_test.rs.