@@ -24,22 +24,22 @@ pull request if you need this.
2424## Example
2525
2626``` rust
27- use multiple_errors :: {fail_all_vec, return_multiple_errors};
27+ use multiple_errors :: {fail_all_vec, return_multiple_errors, CollectVecResult };
2828use multiple_errors :: testing_prelude :: * ;
29-
30- // fail_all_vec:
29+
30+ assert_eq! (
31+ [Err (ErrA ), Ok (A ), Err (ErrA )]. into_iter (). collect_vec_result (),
32+ // Collected all errors, not just the first one
33+ Err (vec! [ErrA , ErrA ])
34+ );
3135
3236let err = fail_all_vec (
3337 vec! [Ok (A ), Err (ErrA ), Ok (A )],
3438 | res | res . err (). map (HighLevelErr :: from ). unwrap_or (HighLevelErr :: B (ErrB ))
3539);
40+ // Same length as the original, each element turned into an error.
3641assert_eq! (err , Err (vec! [ErrB . into (), ErrA . into (), ErrB . into ()]));
3742
38- let ok = fail_all_vec (vec! [Ok (A ), Ok (A )], | _ : Result <_ , ErrA >| ErrC );
39- assert_eq! (ok , Ok (vec! [A , A ]));
40-
41- // return_multiple_errors:
42-
4343fn a_b_c () -> Result <(A , B , C ), Vec <HighLevelErr >> {
4444 return_multiple_errors! (
4545 let mut errors : Vec <HighLevelErr > = vec! [];
@@ -74,7 +74,11 @@ fn a_b_c() -> Result<(A, B, C), Vec<HighLevelErr>> {
7474 > Partition a sequence of Results into one list of all the Ok elements and
7575 > another list of all the Err elements.
7676
77- This is often useful, use ` itertools ` for this.
77+ If you need both lists, just use
78+ [ itertools] ( https://github.com/rust-itertools/itertools ) . If you discard
79+ ` Ok ` s in case of errors, you can use
80+ ` CollectVecResult::collect_vec_result() ` that returns
81+ ` Result<Vec<T>, Vec<E>> ` . It's more precise and efficient.
7882
7983## License
8084
0 commit comments