UniPipe

A simple Rust pipe abstraction that extends to iterator and stream.
Installation
cargo add unipipe
Usage
use unipipe::{UniPipe, unipipe};
pub struct MyPipe {
state: u32,
}
impl UniPipe for MyPipe {
type Input = u32;
type Output = u32;
fn next(&mut self, input: Option<Self::Input>) -> Option<Self::Output> {
if let Some(input) = input {
self.state += input;
Some(self.state)
} else {
None
}
}
}
#[unipipe(iterator, try_iterator, stream, try_stream)]
impl MyPipe {
pub fn new() -> Self {
Self { state: 0 }
}
pub fn new_with_state(state: u32) -> Self {
Self { state }
}
pub fn custom_pipe() -> Self {
Self { state: 0 }
}
}
To use generated methods from other files, you need to import the generated traits accordingly.
use my_pipe::MyPipeUniPipeIteratorExt as _;
let mut iter = vec![1, 2, 3, 4, 5].into_iter().my_pipe();
License
This project is licensed under the MIT License - see the LICENSE file for details.