rust/tests/coverage-map/status-quo/yield.rs

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

38 lines
933 B
Rust
Raw Normal View History

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