pushgen

Crates.iopushgen
lib.rspushgen
version0.0.2
sourcesrc
created_at2021-06-29 11:35:30.656332
updated_at2021-08-02 11:48:23.557203
descriptionPush-style design pattern for processing of ranges and data-streams.
homepagehttps://github.com/AndWass/pushgen
repositoryhttps://github.com/AndWass/pushgen
max_upload_size
id416126
size232,097
Andreas W (AndWass)

documentation

https://docs.rs/pushgen

README

pushgen

Crates.io https://docs.rs/pushgen

API of main branch

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).

Example

fn process(x: i32) { /*...*/ }
let data = [1, 2, 3, 4, 5];

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

can be rewritten as

use pushgen::{SliceGenerator, GeneratorExt};
fn process(_x: i32) { /*...*/ }
let data = [1, 2, 3, 4, 5];
SliceGenerator::new(&data).filter(|x| *x % 2 == 0).map(|x| x * 3).for_each(process);

Performance

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.

Commit count: 236

cargo fmt