I'm trying to figure out how to return a window of elements from a vector that I've first filtered without copying it to a new vector.
So this is the naive approach which works fine but I think will end up allocating a new vector from line 5 which I don't really want to do.
let mut buf = Vec::new();
file.read_to_end(&mut buf);
// Do some filtering of the read file and create a new vector for subsequent processing
let iter = buf.iter().filter(|&x| *x != 10 && *x != 13);
let clean_buf = Vec::from_iter(iter);
for iter in clean_buf.windows(13) {
print!("{}",iter.len());
}
Alternative approach where I could use a chain()? to achieve the same thing without copying into a new Vec
for iter in buf.iter().filter(|&x| *x != 10 && *x != 13) {
let window = ???
}