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

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

35 lines
964 B
Rust
Raw Normal View History

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