I have a long vector with data. I want to split it into equally-sized chunks and then process each chunk in a separate thread. Here's an example:
use std::thread;
use std::sync::Arc;
fn main() {
let data = vec![0, 1, 2];
let data_chunks = Arc::new(data.chunks(2));
let data_clone = data_chunks.clone();
thread::spawn(move || {
data_clone;
});
}
However, this fails with an error saying "`data` does not live long enough". What would be the right way to split a similar vector for processing in multiple threads?