Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
207: Added the ability to collect a stream of results r=yoshuawuyts a=sunjay As requested here: https://twitter.com/yoshuawuyts/status/1174026374316773377 The standard library has a very useful implementation of `FromIterator` that takes an iterator of `Result<T, E>` values and is able to produce a value of type `Result<Vec<T>, E>`. I asked for this in `async-std` and @yoshuawuyts recommended that I contribute the impl. It turns out that the implementation in the standard library is even more general than I initially thought. It allows any collection that implements `FromIterator` to be collected from an iterator of `Result<T, E>` values. That means that you can collect into `Result<Vec<T>, E>`, `Result<HashSet<T>, E>`, etc. I wanted to add a similarly generic impl for this crate so we can also support collecting into any collection that implements `FromStream`. The implementation for this is based heavily on [what exists in `std`](https://github.com/rust-lang/rust/blob/9150f844e2624eb013ec78ca08c1d416e6644026/src/libcore/result.rs#L1379-L1429). I made a new `result` module since that's where this impl is in `std`. I still wanted to maintain the conventions of this repo, so I copied the `vec` module that @yoshuawuyts created in #125. Much like in that PR, the new `result` module is private. There is a doctest in the documentation for `collect` that both teaches that this feature exists and tests that it works in some simple cases. ## Documentation Screenshot  Co-authored-by: Sunjay Varma <[email protected]>
- Loading branch information