pub trait Pipe<T> {
type Output;
// Required method
fn complete(self, value: T) -> Self::Output;
}
Expand description
The Pipe
trait has to be implemented by, well… pipes.
Anything that implements this is usable as a pipe where the
item in the pipeline (at said pipe’s position) is of type T
.
§Implementing your own pipe
The Pipe
trait is public, meaning you can totally implement
your own pipes. Here is an example of how.
use tuppipe::*;
struct Subtractor<const N: i32>;
impl<const N: i32> Pipe<i32> for Subtractor<N> {
type Output = i32;
fn complete(self, value: i32) -> Self::Output {
value - N
}
}
assert_eq!(-2, pipe(0) >> Subtractor::<2>)