rust/tests/ui/coroutine/issue-69039.rs

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

36 lines
982 B
Rust
Raw Normal View History

2020-02-19 22:44:53 +00:00
//@ run-pass
2023-10-19 21:46:28 +00:00
#![feature(coroutines, coroutine_trait)]
2020-02-19 22:44:53 +00:00
2023-10-19 16:06:43 +00:00
use std::ops::{Coroutine, CoroutineState};
2020-02-19 22:44:53 +00:00
fn mkstr(my_name: String, my_mood: String) -> String {
format!("{} is {}", my_name.trim(), my_mood.trim())
}
2023-10-19 16:06:43 +00:00
fn my_scenario() -> impl Coroutine<String, Yield = &'static str, Return = String> {
#[coroutine]
2020-02-19 22:44:53 +00:00
|_arg: String| {
let my_name = yield "What is your name?";
let my_mood = yield "How are you feeling?";
mkstr(my_name, my_mood)
2020-02-19 22:44:53 +00:00
}
}
fn main() {
let mut my_session = Box::pin(my_scenario());
assert_eq!(
my_session.as_mut().resume("_arg".to_string()),
2023-10-19 16:06:43 +00:00
CoroutineState::Yielded("What is your name?")
2020-02-19 22:44:53 +00:00
);
assert_eq!(
my_session.as_mut().resume("Your Name".to_string()),
2023-10-19 16:06:43 +00:00
CoroutineState::Yielded("How are you feeling?")
2020-02-19 22:44:53 +00:00
);
assert_eq!(
my_session.as_mut().resume("Sensory Organs".to_string()),
2023-10-19 16:06:43 +00:00
CoroutineState::Complete("Your Name is Sensory Organs".to_string())
2020-02-19 22:44:53 +00:00
);
}