1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crateErrorVec;
/// Extend [Iterator] with `Item = Result<T, E>` to support gathering multiple errors.
///
/// # Example - Fail on First Error
///
/// One common pattern is processing an iterator over `Result` and propagating the first error
/// encountered which is facilitated in [std] with the [FromIterator] impl on [Result]:
///
/// ```
/// use std::path::Path;
///
/// fn read_paths_fail_fast<'a, I>(paths: I) -> std::io::Result<Vec<String>>
/// where I: Iterator<Item = &'a Path>,
/// {
/// paths.map(std::fs::read_to_string).collect()
/// }
/// ```
///
/// # Example - Gather all Errors
///
/// However, another common pattern is to gather all possible errors. This pattern is often useful
/// in user-facing error reporting, such as a compiler reporting all detected errors when building
/// a source project. [ResultIterator] along with [ErrorVec] streamline this pattern:
///
/// ```
/// use std::path::Path;
/// use errorvec::{ErrorVec, ResultIterator};
///
/// fn read_paths_gathering_all_errors<'a, I>(paths: I) -> Result<Vec<String>, ErrorVec<std::io::Error>>
/// where I: Iterator<Item = &'a Path>,
/// {
/// paths.map(std::fs::read_to_string).into_errorvec_result()
/// }
/// ```