Expand description
§A pipe operator-like experience in Rust.
This crate provides a handy Pipe
trait that you can implement for arbitrary types
to use them as pipes in a pipeline.
§Usage
In the example below the pipe
function generates a PartialPipe
which can be used to “complete” (invoke) any type that implements Pipe
using the
shift right (>>
) operator.
use tuppipe::pipe;
const fn add_one(to: i32) -> i32 {
to + 1
}
assert_eq!(2, pipe(0) >> (add_one, add_one));
The first element in the tuple (the tuple being the pipeline) after >>
, will receive the 0i32
that you see in the pipe
invocation. The second element in the pipeline will receive the output
from the first element in the pipeline, and so on.
§Default implementations of Pipe
Note that Pipe
is currently implemented for both, anything that implements FnOnce
from the standard library and for any tuple with up to 16 elements where each element in the tuple
itself implements Pipe
itself as well.
This means that if you really want a pipeline that’s longer than a tuple of 16 elements, you can pretty much infinitely nest tuples in one another.
You can check out the docs for more documentation and examples.
Modules§
Structs§
- The
PartialIgnoredPipeline
struct is essentially the same as thePartialPipeline
struct, however with this struct the result of your pipeline will be ignored, and you will instead receive the unit type()
as a result. - This
PartialPipeline
struct is a necessary wrapper around a genericT
, to implement a foreign trait (the pipe operator of choice,Shr
) for any arbitrary type.
Traits§
- 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 typeT
.
Functions§
- The
ignore
function makes a partial ignored pipeline. This means that no matter the result of your pipeline, the result of it will be ignored, and you will receive the unit type()
instead.