Crates.io | unchained |
lib.rs | unchained |
version | 0.1.3 |
source | src |
created_at | 2019-07-27 23:53:48.626674 |
updated_at | 2019-07-28 07:10:24.558756 |
description | Unchained Iteration |
homepage | |
repository | https://github.com/sigmaSd/Unchained |
max_upload_size | |
id | 152228 |
size | 6,915 |
Trait that allows iterating on a collection while appliyng a function with a thread per item
use unchained::Unchained;
// download all the pages at the same time by using a thread per item
fn download_all {
let pages = vec![
"https://doc.rust-lang.org/stable/std/",
"https://doc.rust-lang.org/stable/std/#modules",
"https://doc.rust-lang.org/stable/std/#primitives",
"https://doc.rust-lang.org/stable/std/#macros",
"https://doc.rust-lang.org/stable/std/prelude/index.html",
"https://doc.rust-lang.org/stable/book/ch03-02-data-types.html",
];
download_all_inner(pages);
}
fn download_all_inner(pages: Vec<&'static str>) {
pages
.into_iter()
.unchained_for_each(|page| {
println!(
"{}:\n\n{}",
&page,
String::from_utf8(
std::process::Command::new("curl")
.arg(&page)
.output()
.unwrap()
.stdout
)
.unwrap()
);
println!("\n#######################\n");
});
}
You can also checkout rustman that uses Unchained
to parallelize search requests