unchained

Crates.iounchained
lib.rsunchained
version0.1.3
sourcesrc
created_at2019-07-27 23:53:48.626674
updated_at2019-07-28 07:10:24.558756
descriptionUnchained Iteration
homepage
repositoryhttps://github.com/sigmaSd/Unchained
max_upload_size
id152228
size6,915
Bedis Nbiba (sigmaSd)

documentation

README

Unchained

Trait that allows iterating on a collection while appliyng a function with a thread per item

Example

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

Commit count: 16

cargo fmt