More AsyncIterator
helper functions
#599
Labels
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
I-async-nominated
T-libs-api
Uh oh!
There was an error while loading. Please reload this page.
Proposal
Problem statement
Working with
AsyncIterator
s is currently very difficult due to a lack of helper functions (Iterator
provides 75 methods, whileAsyncIterator
provides onlysize_hint
).Motivating examples or use cases
This block of code (from https://github.com/Kobzol/async-iterator-examples/blob/25e239bd708943f4971366b591a99e918771e030/json-line-parser/src/bin/server.rs#L67-L76)
would be absurd to write with a standard
Iterator
. It would be much more idiomatic and readable to write something like this:Depending on which methods are available on Message, it might be desirable to eliminate the match statement in favor of a filter and a map separately. There are a plethora of more readable options due to
Iterator
's helper functions, and it's a big part of what makes working with Iterators in Rust so enjoyable.Solution sketch
There are many useful methods on
Iterator
, but these seem like a reasonable subset with which to start. I includedfuse()
here because its use case is mentioned in the documentation, which is how I got here. I also addedfold()
because (at least in my experience) while it's not the most common adapter, it's a very powerful one, and one through which many others are implemented.Note that the returned structs are not the same as the ones for
Iterator
and implementAsyncIterator
instead.Alternatives
AsyncIterator
is stabilized. This seems bad because more people are likely to use it if it's ergonomic.Iterator
helper functions could be chosen, or new async-specific functions could be designed. I have no strong opinions on this either.Links and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: