Skip to content

Allow StreamExt::collect to return a Result like Iterator::collect #2979

@PacificBird

Description

@PacificBird

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions