Function vector::sinks::prelude::future::always_ready

pub fn always_ready<T, F>(prod: F) -> AlwaysReady<T, F> 
where F: Fn() -> T,
Expand description

Creates a future that is always immediately ready with a value.

This is particularly useful in avoiding a heap allocation when an API needs [Box<dyn Future<Output = T>>], as AlwaysReady does not have to store a boolean for is_finished.

§Examples

use std::mem::size_of_val;

use futures::future;

let a = future::always_ready(|| 1);
assert_eq!(size_of_val(&a), 0);
assert_eq!(a.await, 1);
assert_eq!(a.await, 1);