rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.29k stars 607 forks source link

Add a helper for always ready futures #2825

Closed GnomedDev closed 4 months ago

GnomedDev commented 5 months ago

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 commented 4 months ago

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

taiki-e commented 4 months ago

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.