mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
aef0f4024a
And suggest adding the `#[coroutine]` to the closure
23 lines
432 B
Rust
23 lines
432 B
Rust
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
|
|
|
use std::marker::Unpin;
|
|
use std::ops::Coroutine;
|
|
|
|
pub fn foo() -> impl Coroutine<(), Yield = (), Return = ()> {
|
|
#[coroutine]
|
|
|| {
|
|
if false {
|
|
yield;
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn bar<T: 'static>(t: T) -> Box<Coroutine<(), Yield = T, Return = ()> + Unpin> {
|
|
Box::new(
|
|
#[coroutine]
|
|
|| {
|
|
yield t;
|
|
},
|
|
)
|
|
}
|