futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

Allow `StreamExt::collect` to return a `Result` like `Iterator::collect`

Open PacificBird opened this issue 2 months ago • 0 comments

I have been familiarizing myself with Streams since my project at work makes heavy use of iterations that involve async I/O (such as transforming datasets containing transformations that require API calls to resolve). One thing I noticed was that, unlike sync iterators, streams require you to use .try_collect to collect into a Result. I found the following reply to an issue discussing the same topic from before async fn in traits was stabilized:

Collecting into a Result<Collection<_>, _> specifically can be done via try_collect.

It could be possible to add a trait like FromStream as an equivalent to FromIterator to use instead of Default + Extend, but that would want to involve async fn-in-traits, which is not possible today (you can see that async-std::stream::FromStream forces boxing of the future and isn't Send, which would be unacceptable long term.

Originally posted by @Nemo157 in #1988

Is there still a blocker to allowing StreamExt::collect to collect into a Result?

PacificBird avatar Nov 15 '25 00:11 PacificBird