# `all-the-errors`
[](https://crates.io/crates/clap)
[](https://docs.rs/all-the-errors)
[](LICENSE)
[crates_dot_io]: https://crates.io/crates/all-the-errors
 [^memesrc]
A silly little trait with a few methods for getting _all_ the errors out of a
`Iterator<Item=Result<T,E>>`.
When you bring the trait `all_the_errors::CollectAllTheErrors` into scope,
it automatically implements 3 methods on `Iterator`s: `partition_results`,
`collect_all_results`, and `collect_oks_or_iter_errs`.
No-std compatible: does not use `std` internally (although it's
mostly _useful_ with allocation, as in the example below).
## Example: collecting into `Vec`s
For clarity, let's assume you want to collect results into `Vec`s
(see the docs for the generic signature).
The methods available on an `iter: Iterable<Item=Result<T, E>>` are:
1. `iter.partition_results() -> (Vec<T>, Vec<E>)`
2. `iter.collect_results() -> Result<Vec<T>, Vec<E>>`
3. `iter.collect_oks_or_iter_errs() -> Result<Vec<T>, impl Iterator<Item=E>>`
For example:
```rust
use all_the_errors::CollectAllTheErrors;
assert_eq!(
[Ok(1), Ok(2), Err("a"), Err("b")]
.into_iter()
.partition_results(),
(vec![1, 2], vec!["a", "b"])
);
assert_eq!(
[Ok(1), Ok(2)]
.into_iter()
.collect_results(),
Ok(vec![1, 2])
);
assert_eq!(
[Ok(1), Ok(2), Err("a"), Err("b")]
.into_iter()
.collect_results(),
Err(vec!["a", "b"])
);
```
## Why?
This is useful because, given the stdlib's trait implementations,
`Iterator::collect` will stop collecting results after the first error
(e.g., collecting an `Iterator<Item=Result<T, E>>`
into a `Result<Vec<T>, E>`). So it gives you all the `T`s, but just one `E`.
`Iterator::partition` gives you the tuple
`(Vec<Result<T, E>>, Vec<Result<T,E>>)`, which is annoying
because you have to unwrap everything your own self
_and_ it requires 2 unnecessary intermediate allocations.
So I use this trait because sometimes I want _all_ the errors - e.g.,
`Result<Vec<T>, Vec<E>>`, or even all the results as `(Vec<T>, Vec<E>)`.
## License and Copyright Boilerplate
- **License**:
This project is provided under the [MIT License](./LICENSE).
- **Copyrightability**:
All material here was written by (and for) the human authors.
No LLM-derived content is present in any form.