I'm searching a way to pass a variable url_path to this thread, as in this code:
async fn download_dist(all_paths: Vec<String>, mode: &str) {
let mut download_path = "";
let mut root_path = "";
let mut url_path = String::new();
if mode.contains("pool") {
root_path = POOL_ROOT_PATH;
url_path = format!("http://{}/{}", DEBIAN_REPOSITORY, DEBIAN_PATH);
download_path = DEBIAN_POOL_PATH;
} else {
root_path = DIST_ROOT_PATH;
url_path = format!("http://{}/{}/", DEBIAN_REPOSITORY, DEBIAN_DIST_PATH);
download_path = DEBIAN_DIST_PATH;
}
let responses = futures::stream::iter(all_paths.into_iter().map(move |path| {
tokio::spawn(async move {
println!("{}", url_path);
})
}))
.buffer_unordered(10)
.collect::<Vec<_>>();
responses.await;
}
Error is :
cannot move out of url_path, a captured variable in an FnMut closure
move out of url_path occurs here
mutor better create a copy in side of the async blocklet url_path = url_path.