This package implements "sliding window" functionality for any iterator over a Clone
able item.
use iterslide::SlideIterator;
fn main() {
let v: Vec<i8> = vec![1, 2, 3, 4, 5];
for window in v.slide(3) {
// window is a VecDeque<i8>
println!("{:?}", window);
}
}
Output:
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
-
Rust's
windows
method for slices does what you would expect. This does no allocation. However, this is only implemented for slices. -
itertools'
tuple_windows
method returns a sliding window iterator over tuples instead ofVecDeques
. This saves aVecDeque
allocation in construction of the iterator. However,tuple_windows
is limited to window sizes of at most 4.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.