rust/tests/coverage/yield.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
981 B
Rust
Raw Normal View History

#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
#![allow(unused_assignments)]
2023-10-19 16:06:43 +00:00
use std::ops::{Coroutine, CoroutineState};
use std::pin::Pin;
fn main() {
let mut coroutine = #[coroutine] || {
yield 1;
return "foo";
};
2023-10-19 21:46:28 +00:00
match Pin::new(&mut coroutine).resume(()) {
2023-10-19 16:06:43 +00:00
CoroutineState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
2023-10-19 21:46:28 +00:00
match Pin::new(&mut coroutine).resume(()) {
2023-10-19 16:06:43 +00:00
CoroutineState::Complete("foo") => {}
_ => panic!("unexpected value from resume"),
}
let mut coroutine = #[coroutine] || {
yield 1;
yield 2;
yield 3;
return "foo";
};
2023-10-19 21:46:28 +00:00
match Pin::new(&mut coroutine).resume(()) {
2023-10-19 16:06:43 +00:00
CoroutineState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
2023-10-19 21:46:28 +00:00
match Pin::new(&mut coroutine).resume(()) {
2023-10-19 16:06:43 +00:00
CoroutineState::Yielded(2) => {}
_ => panic!("unexpected value from resume"),
}
}