Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the once_future() combinator #59

Merged
merged 6 commits into from
Nov 6, 2022
Merged

Add the once_future() combinator #59

merged 6 commits into from
Nov 6, 2022

Conversation

notgull
Copy link
Member

@notgull notgull commented Sep 5, 2022

Resolves #52

@taiki-e
Copy link
Collaborator

taiki-e commented Sep 10, 2022

Why does this add both freestanding function and method?

@notgull
Copy link
Member Author

notgull commented Sep 10, 2022

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

@taiki-e
Copy link
Collaborator

taiki-e commented Sep 10, 2022

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: rust-lang/futures-rs#1215

@taiki-e
Copy link
Collaborator

taiki-e commented Sep 20, 2022

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).

@notgull
Copy link
Member Author

notgull commented Sep 20, 2022

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

@taiki-e
Copy link
Collaborator

taiki-e commented Sep 20, 2022

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
Copy link
Collaborator

taiki-e commented Sep 20, 2022

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

@zeenix
Copy link
Member

zeenix commented Sep 20, 2022

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

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

@notgull
Copy link
Member Author

notgull commented Sep 20, 2022

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().

src/future.rs Outdated Show resolved Hide resolved
@fogti
Copy link
Member

fogti commented Sep 21, 2022

@notgull
Copy link
Member Author

notgull commented Sep 21, 2022

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

@fogti
Copy link
Member

fogti commented Nov 6, 2022

this should be squash-merged.

@notgull notgull merged commit 723ae31 into master Nov 6, 2022
@notgull notgull deleted the into-stream branch November 6, 2022 23:11
@taiki-e taiki-e changed the title Add the into_stream() combinator Add the once_future() combinator Nov 7, 2022
@notgull notgull mentioned this pull request Apr 7, 2023
notgull added a commit that referenced this pull request Apr 7, 2023
- Unbind Debug implementations of BufReader and BufWriter. (#49)
- Add the once_future() combinator. (#59)
- Add a combinator for temporarily using an AsyncRead/AsyncWrite as Read/Write. (#62)
- Implement more methods for stream::BlockOn. (#68)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Method for creating a stream from a future
4 participants