pub trait Itertools: Iterator {
// Provided method
fn try_collect<T, U, E>(self) -> Result<U, E>
where Self: Sized + Iterator<Item = Result<T, E>>,
Result<U, E>: FromIterator<Result<T, E>> { ... }
}
Expand description
Extra methods for Iterator. Copied from itertools.
Licensed under MIT.
Provided Methods§
Sourcefn try_collect<T, U, E>(self) -> Result<U, E>
fn try_collect<T, U, E>(self) -> Result<U, E>
.try_collect()
is more convenient way of writing
.collect::<Result<_, _>>()
§Example
use std::{fs, io};
use itertools::Itertools;
fn process_dir_entries(entries: &[fs::DirEntry]) {
// ...
}
fn do_stuff() -> std::io::Result<()> {
let entries: Vec<_> = fs::read_dir(".")?.try_collect()?;
process_dir_entries(&entries);
Ok(())
}