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 a helper for always ready futures #2825

Merged
merged 6 commits into from Mar 9, 2024

Conversation

GnomedDev
Copy link
Contributor

Currently, there is no easy way to wrap a given value in a zst future, so this PR adds one. The always_ready function has to take a closure to allow it to yield non-zsts without having to carry around it's size.

This is particularly useful in avoiding a heap allocation when a library needs Pin<Box<dyn Future<Output<T>>>, as a simple empty async block still has to allocate a boolean in this example for "has been polled".

@GnomedDev
Copy link
Contributor Author

Hey, @taiki-e, just letting you know I responded to your review comment.

@taiki-e
Copy link
Member

taiki-e commented Mar 8, 2024

This is particularly useful in avoiding a heap allocation when a library needs Pin<Box<dyn Future<Output<T>>>

I think adding this statement to the document would be helpful.

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@taiki-e taiki-e merged commit 570c4e7 into rust-lang:master Mar 9, 2024
24 checks passed
@taiki-e taiki-e added A-future Area: futures::future 0.3-backport: pending The maintainer accepted to backport this to the 0.3 branch, but backport has not been done yet. labels Mar 9, 2024
@GnomedDev GnomedDev deleted the always-ready branch March 9, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.3-backport: pending The maintainer accepted to backport this to the 0.3 branch, but backport has not been done yet. A-future Area: futures::future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants