Function aoc::year2022::day05::play

source ·
fn play(input: &(Vec<Vec<char>>, Vec<[usize; 3]>), reverse: bool) -> String
Expand description

Rust’s borrow checker won’t allow us to mutate 2 nested vecs simulataneously, so we need to use an temporary intermediate vec to store the moving crates. For efficiency we can re-use the same vec to prevent unnecessary memory allocations.

A nice standard library feature is that we can collect an iterator of chars into a String for the final answer.