Open tmandry opened 4 years ago
Doing research on this now :)
I was working on a crate today that models the browsers History API, and found that the concept of a DoubleEndedStream
would be a great tool to model it: the history API is asynchronous and can can be navigated by going forward and backward through "the history stack". Under "future possibilities" it's probably worth mentioning we should explore not only IntoStream
and FromStream
which have clear tie-ins to language features. But we should also look towards filling out the roster of traits we found useful for Iterator
.
Under async_std::stream
we've shown it's possible to create async counterparts to the traits in std::iter
. I'm not sure if it's worth mentioning every one of these, but we've successfully been able to implement the following traits:
DoubleEndedStream # A stream able to yield elements from both ends.
ExactSizeStream # A stream that knows its exact length.
Extend # Extends a collection with the contents of a stream.
FromStream # Conversion from a Stream.
FusedStream # A stream that always continues to yield None when exhausted.
IntoStream # Conversion into a Stream.
Product # Trait to represent types that can be created by multiplying the elements of a stream.
Stream # An asynchronous stream of values.
Sum # Trait to represent types that can be created by summing up a stream.
Got quite a bit more in place with #13.
To do on the next iteration:
Some notes about attached vs detached streams and how interconversion might work (and what hurdles we know of, mostly a question of coherence) can be found in this hackmd:
https://hackmd.io/gHqlQBTiSrexwb-ppRPn-A
Discussion from this point on Zulip
Some concerns that should block opening the RFC
next
method to the stream so it can be used for somethingBox<T>
and other fundamental typesimpl Stream
to impl LendingStream
Hello everyone!
The main two things I would like to see added to the RFC:
next
method requires Self: Unpin
.[async] gen fn
to support borrowing across a yield, it will need to have a pinned receiverasync gen fn() -> impl Stream
is fairly easy, but async for x in y
syntax or whatever would presumably want to pingen fn
either has to disallow borrowing or we need some kind of cleverness we have not yet come up with to "adapt" the return value of a gen fn
to become an Iterator
Stream RFC is open: https://github.com/rust-lang/rfcs/pull/2996
As drafted in #10