frewsxcv / rust-crates-index

Rust library for retrieving and interacting with the crates.io index
https://docs.rs/crates-index/
Apache License 2.0
72 stars 37 forks source link

API error resiliency #24

Closed theduke closed 4 years ago

theduke commented 5 years ago

Useful crate!

I just have one issue: the implementation uses a whole lot of .unwrap(). It's unlikely for failures to occur but very much possible, mostly with IO errors (think directory moved, disk inaccessible, ...) which can become an issue in a long running application.

It would be great to have Crates be Iterator<Item = Result<Crate, Error>> instead.

kornelski commented 4 years ago

There's Crate::new_checked() now. You can iterate over crates yourself. I use this:

let indexed_crates: Result<HashMap<_,_>, _> = crates_io_index.crate_index_paths()
                .par_bridge() // rayon
                .filter_map(|path| {
                    let c = crates_index::Crate::new_checked(path)?;
                    Ok((c.name().to_ascii_lowercase(), c))
                })
                .collect();