As this post says, you can create a vector of closures like this:
let mut xs: Vec<Box<dyn Fn((i32, i32)) -> (i32, i32)>> = vec![
Box::new(move |(x, y)| (y, x)),
Box::new(move |(x, y)| (1 - y, 1 - x)),
];
But why can't you append to it using:
xs.append(Box::new(move |(x, y)| (2 - y, 2 - x)));
This raises the error:
|
162 | xs.append(Box::new(move |(x, y)| (2 - y, 2 - x)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected mutable reference, found struct `std::boxed::Box`
|
= note: expected mutable reference `&mut std::vec::Vec<std::boxed::Box<dyn std::ops::Fn((i32, i32)) -> (i32, i32)>>`
found struct `std::boxed::Box<[closure@src/lib.rs:162:22: 162:50]>`