3 releases
new 0.1.2 | Dec 18, 2024 |
---|---|
0.1.1 | Dec 18, 2024 |
0.1.0 | Dec 18, 2024 |
#1157 in Rust patterns
123 downloads per month
13KB
178 lines
iter-grid
Ideomatic Grid operations via Iterators
The grid-iter crate provides convenient methods to wrap a flat iterator and perform operations on it as if it was a grid.
lib.rs
:
Grids for Iterators
Provides a two dimensional abstraction over Iterators. Intended to be simple, flexible and ideomatic.
use grid_iter::IntoGridIter;
let file:&str = "1,2,3,4,5\n6,7,8,9,10\n11,12,13,14,15";
let columns = file.find('\n').unwrap();
let mut store = file.lines()
.flat_map(|line|line.split(',').map(|s|s.parse().unwrap()))
.collect::<Vec<_>>();
store.iter_mut().into_grid_iter(columns).iter_col(3).for_each(|i| *i= 0);
store.iter_mut().into_grid_iter(columns).iter_row(1).for_each(|i| *i+= 1);
let borrowing_grid = store.iter().into_grid_iter(5);
drop(borrowing_grid);
let capturing_grid = store.iter().into_grid_iter(5);
println!("{:?}", capturing_grid);