try_all/lib.rs
1//! Rust iterator extensions to operate on `Result`s effectively.
2//!
3//! ## [`try_map_all`](crate::TryMapAll::try_map_all)
4//! _and [`try_map_all_opt`](crate::TryMapAllOption::try_map_all_opt)_
5//!
6//! Applies a closure on all items of the iterator until one fails (or all succeed).
7//!
8//! ```rust
9//! # use crate::try_all::*;
10//! fn all_numbers_x2(strs: &Vec<&str>) -> Result<Vec<u64>, std::num::ParseIntError> {
11//! Ok(strs.iter().try_map_all(|s| Ok(s.parse::<u64>()?*2))?.collect())
12//! }
13//! ```
14//!
15//! Respectively, for [`Option`]s:
16//! ```rust
17//! # use crate::try_all::*;
18//! fn not_zero(is: Vec<u64>) -> Option<Vec<u64>> {
19//! Some(is.into_iter().try_map_all_opt(|i| if i > 0 { Some(i) } else { None })?.collect())
20//! }
21//! ```
22//!
23//! _Note: once [#42327](https://github.com/rust-lang/rust/issues/42327) is merged, `try_map_all` will be implemented\* under one name for all try types._
24//!
25//! ## [`try_all`](crate::TryAll::try_all(self))
26//!
27//! Tries all items of the iterator until one fails (or all succeed).
28//!
29//! ```
30//! # use crate::try_all::*;
31//! fn parse_all_numbers(strs: &Vec<&str>) -> Result<Vec<u64>, std::num::ParseIntError> {
32//! Ok(strs.iter().map(|s| s.parse()).try_all()?.collect())
33//! }
34//! ```
35//!
36
37mod iter;
38pub use iter::*;
39mod map;
40pub use map::*;