tokio-rs / async-stream

Asynchronous streams for Rust using async & await notation
Other
636 stars 33 forks source link

stream_mut() equivalent to iter_mut()? #103

Closed dan-da closed 8 months ago

dan-da commented 8 months ago

Hi, thx for this crate. I was able to easily create an async method stream_many() that accepts an impl IntoIter of indexes and returns an impl Stream of key/val pairs for only those indices. pretty cool.

Next I was wondering if there is any way I can write a method that returns a Stream that can mutate &mut self? eg:

/// Returns a stream that allows modifying each value.
pub fn stream_mut(&mut self) -> StreamMut<'_, T> 

Perhaps with some kind of lending iterator?

or any plans in this area?

taiki-e commented 8 months ago

key/val pairs

It looks like you have opened an issue in the wrong repository.

This repository does not contain any map-like structures.

dan-da commented 8 months ago

no, not the wrong repo. The key/val pairs are returned in a tuple, ie impl Stream<Item = (Index, T)> and the method impl uses the async_stream::stream macro to yield the tuple. I only mentioned it to say thx for creating the crate.

Anyway, that is irrelevant to the question, which is about if there is any way to return an async iterator from a collection's method that can mutate the collection.

taiki-e commented 8 months ago

if there is any way to return an async iterator from a collection's method that can mutate the collection.

If the collection has a method that returns a stream, it can be used. Otherwise, I believe you can combine futures::stream::iter with a method that returns an iterator.