Pipa
First Release: 18 Aug 2024
Last Update: 30 Aug 2024
Status: active
Latest Release: v0.4.1
page documentation source
Last Update: 30 Aug 2024
Status: active
Latest Release: v0.4.1
page documentation source
About
Pipe Operator simplifying writing of chain of functions/methods in readable way while also supporting rail-oriented programming handling errors/exceptions. It supports sync functions/methods, async functions/methods, closure, along with Try
-able return value. Read more on README.
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!;
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!;