Again, by putting the collecting loop outside the pool.scope
you are effectively collecting every items into your channel and then recollecting them into a Vec
.
The thread with the collecting loop (using for .. in
or iterator methods) should live inside the thread pool's scope.
And that :
let mut stored_statements: Vec<StoredStatements> = Vec::new();
for (hostname_port, detail_snapshot_time, statements) in rx {
add_to_statements_vector(statements, hostname_port, detail_snapshot_time, &mut stored_statements);
}
stored_statements
Would be better expressed in Rust with :
rx.into_iter()
.map(|(hostname_port, detail_snapshot_time, statements)| make_statement(statements, hostname_port, detail_snapshot_time)
.collect();
Which avoids the temporary mutable borrow.
See this playground for a few improvements you could make.