Deprecated: A threaded version of the map function
-
TODO
-
It seems this crate is not available any more.
-
Using the threaded-map crate we can use the threadpool as the
mapfunction.
use threaded_map::ThreadedMappable;
fn main() {
let items = vec![1, 2, 3, 4, 5, 6];
let target = items.iter().map(|num| double(*num)).collect::<Vec<_>>();
println!("{:?}", target);
let results = items
.into_iter()
.threaded_map(double, None)
.collect::<Vec<_>>();
println!("{:?}", results);
assert_eq!(results, target);
}
fn double(n: i32) -> i32 {
println!("{:?}", std::thread::current().id());
n * 2
}
[package]
name = "map-with-thread"
version = "0.1.0"
edition = "2024"
[dependencies]
threaded-map = "0.2.0"