Expand description
§pipei
A zero-cost library for chaining multi-argument function calls in method syntax.
pipe allows writing x.pipe(f)(y, z) instead of f(x, y, z) by currying the receiver into the first argument.
tap provides the same call form for side effects: it passes the value to a function for inspection or mutation and then returns the original value.
§Extension traits
Pipe::pipe: Curriesselfinto the first argument of a function, returning the result.Tap::tap: Passesselfto a function for inspection or mutation, then returns the original (now possibly modified) value.TapWith::tap_with: Liketap, but first applies a projection; the side effect only runs if the projection returnsSome.
fn add(a: i32, b: i32) -> i32 { a + b }
fn log(x: &i32) { println!("{x}"); }
let result = 1
.pipe(add)(2)
.tap(log)()
.pipe(Option::Some)();
assert_eq!(result, Some(3));