Crate pushgen[][src]

Expand description

Push-style design pattern for processing of ranges and data-streams.

This is a Rust-based approach to the design pattern described by transrangers. While the discussion linked targets C++, the same basic principle of pull-based iterators applies to Rust as well (with some modifications since Rust doesn’t have a concept of an end iterator like C++ does).


for item in data.iter().filter(|x| *x % 2 == 0).map(|x| x * 3) {

can be rewritten as

use pushgen::{SliceGenerator, GeneratorExt};
// Assume data is a slice
SliceGenerator::new(&data).filter(|x| *x % 2 == 0).map(|x| x * 3).for_each(process);


std: Enable boxing and trait implementations for types that requires std. If this feature is disabled, pushgen is no_std. This is enabled by default.

test: Enable test tools that can be used to test generators and adaptors. This is disabled by default.


I make no performance-claims, however there are some benchmarked cases where the push-based approach wins over the iterator approach, but I have made no attempts to analyze this in any depth.


Implements various generators.

Generator adaptor implementations. See GeneratorExt for more info.



A generator that generates values from a slice.


The enum Either with variants Left and Right is a general purpose sum type with two cases.

The result of generator runs.

The result value of a try_* reduction.

Value-consumption result.


Conversion from a Generator.

Trait for generating values into a closure.

Provides extension-methods for all generators.


Creates a new generator where each iteration calls the provided closure F: FnMut() -> Option<T>.

Creates a generator that wraps an Iterator.