File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ // run-pass
2
+
3
+ #![ feature( generators, generator_trait) ]
4
+
5
+ use std:: ops:: { Generator , GeneratorState } ;
6
+
7
+ fn my_scenario ( ) -> impl Generator < String , Yield = & ' static str , Return = String > {
8
+ |_arg : String | {
9
+ let my_name = yield "What is your name?" ;
10
+ let my_mood = yield "How are you feeling?" ;
11
+ format ! ( "{} is {}" , my_name. trim( ) , my_mood. trim( ) )
12
+ }
13
+ }
14
+
15
+ fn main ( ) {
16
+ let mut my_session = Box :: pin ( my_scenario ( ) ) ;
17
+
18
+ assert_eq ! (
19
+ my_session. as_mut( ) . resume( "_arg" . to_string( ) ) ,
20
+ GeneratorState :: Yielded ( "What is your name?" )
21
+ ) ;
22
+ assert_eq ! (
23
+ my_session. as_mut( ) . resume( "Your Name" . to_string( ) ) ,
24
+ GeneratorState :: Yielded ( "How are you feeling?" )
25
+ ) ;
26
+ assert_eq ! (
27
+ my_session. as_mut( ) . resume( "Sensory Organs" . to_string( ) ) ,
28
+ GeneratorState :: Complete ( "Your Name is Sensory Organs" . to_string( ) )
29
+ ) ;
30
+ }
You can’t perform that action at this time.
0 commit comments