piping
provides a pipe!
macro that allows you to use the pipeline operator in Rust.
```rs
fn add(a: usize, b: usize) -> usize { a + b }
// Compiles to add(2, 2) for no runtime performance hit! add!(b = 2); // 4 ```
Documentation is provided on docs.rs.
```rs fn add(a: usize, b: usize) -> usize { a + b }
fn origanddouble(num: usize) -> (usize, usize) { (num, num * 2) }
let num = 4;
let piped = pipe! { num |> add(2, ) |> origanddouble(), (_, doubled) |> doubled as isize, };
// Expands to... let piped = { let pipelinevalue = num; let pipelinevalue = add(2, pipelinevalue); let (, doubled) = origanddouble(pipeline_value); doubled as isize }; ```
You can pass any expression in as the input.
Notice that you can chain pipelines with ,
s to destructure the result of the previous pipeline.
The macro also tries to optimize the generated code to minimize the amount of reassigning done.