Type Alias genawaiter::sync::GenBoxed

source ·
pub type GenBoxed<Y, R = (), C = ()> = Gen<Y, R, Pin<Box<dyn Future<Output = C> + Send>>>;
Expand description

This is a type alias for generators which can be stored in a 'static. It’s only really needed to help the compiler’s type inference along.

Aliased Type§

struct GenBoxed<Y, R = (), C = ()> { /* private fields */ }

Implementations§

source§

impl<Y, R, C> GenBoxed<Y, R, C>

source

pub fn new_boxed<F>(producer: impl FnOnce(Co<Y, R>) -> F) -> Self
where F: Future<Output = C> + Send + 'static,

Creates a new generator with a boxed future, so it can be stored in a static.

This works exactly the same as Gen::new with an immediately boxed future.

This method exists solely to help the compiler with type inference. These two lines are equivalent, except that the compiler cannot infer the correct type on the second line:

let _: GenBoxed<i32> = Gen::new_boxed(|co| producer(co));
let _: GenBoxed<i32> = Gen::new(|co| Box::pin(producer(co)));