Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Paginate Over A Vec In Rust Using chunks

Code

fn main() {
  let data = vec!["a", "b", "c", "d", "e", "f", "g"];
  data.chunks(2).for_each(|w| { dbg!(w); () });
}

Results

[_active_nvim_run:3] w = [
    "a",
    "b",
]
[_active_nvim_run:3] w = [
    "c",
    "d",
]
[_active_nvim_run:3] w = [
    "e",
    "f",
]
[_active_nvim_run:3] w = [
    "g",
]