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

Add the into_stream() combinator

Open notgull opened this issue 3 years ago • 11 comments

Resolves #52

notgull avatar Sep 05 '22 02:09 notgull

Why does this add both freestanding function and method?

taiki-e avatar Sep 10 '22 13:09 taiki-e

I assumed that was the status quo for futures_lite, like how zip and or are methods.

notgull avatar Sep 10 '22 14:09 notgull

I guess it is only happening with methods that take two or more futures/streams. (e.g., catch_unwind is trait method only) There has been discussion in the past in futures that freestanding functions are preferred for such methods: https://github.com/rust-lang/futures-rs/issues/1215

taiki-e avatar Sep 10 '22 14:09 taiki-e

It seems you have removed the trait method, but I have the impression that into_ is a prefix that is often used in the method (e.g., String::into_bytes, {BufReader,BufWriter}::into_inner).

taiki-e avatar Sep 20 '22 17:09 taiki-e

You're right. How would you feel about just the name stream()?

notgull avatar Sep 20 '22 17:09 notgull

Maybe stream::from_future?

That said, I have no strong opinion on this as I tend to prefer the futures's APIs that take the future as an argument (i.e., I think stream::once is the ideal name here).

taiki-e avatar Sep 20 '22 17:09 taiki-e

@smol-rs/admins: Any thoughts on the API here?

taiki-e avatar Sep 20 '22 17:09 taiki-e

@smol-rs/admins: Any thoughts on the API here?

I agree with you about the naming. stream::once seems better to me as well.

zeenix avatar Sep 20 '22 17:09 zeenix

I like the idea of stream::once, however, that method already exits and just yields a single value without being asynchronous. I renamed this type to stream::once_future().

notgull avatar Sep 20 '22 18:09 notgull

So this does just the same as https://docs.rs/futures-util/0.3.24/futures_util/future/struct.IntoStream.html ? / https://docs.rs/futures-util/0.3.24/futures_util/stream/struct.Once.html

fogti avatar Sep 21 '22 18:09 fogti

Yes, the idea is to give the user the ability to turn a Future into a Stream.

notgull avatar Sep 21 '22 19:09 notgull

this should be squash-merged.

fogti avatar Nov 06 '22 21:11 fogti