1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use_prelude!;
/// The trait implemented by [`coroutineFn`]s **with resume arguments**.
///
/// # Example
///
/// ```rust
/// use ::next_gen::prelude::*;
///
/// fn main ()
/// {
/// #[coroutine(i32)]
/// fn coro_fn (b: bool, mut arg @ yield_: u8)
/// -> &'static str
/// {
/// assert_eq!(arg, 42);
/// arg = yield_!(1);
/// assert_eq!(arg, 27);
/// return "foo";
/// }
///
/// mk_coro!(let mut coro = coro_fn());
///
/// let mut next = |arg: u8| coro.as_mut().resume_with(arg);
///
/// match next(42) {
/// | GeneratorState::Yield(yielded) => assert_eq!(yielded, 1_i32),
/// | GeneratorState::Return(_) => unreachable!(),
/// }
/// match next(27) {
/// | GeneratorState::Yield(_) => unreachable!(),
/// | GeneratorState::Return(returned) => assert_eq!(returned, "foo"),
/// }
/// }
/// ```
///
/// # `Coroutine` _vs._ `Generator`
///
/// - A `Generator` is a `Coroutine where Resume = ()`,
///
/// - or another way to see it is that a `Coroutine` is a `Generator` which
/// has been enhanced with support for resume arguments.
///
/// We thus have the following impls:
///
/// ```rust
/// # const _: &str = stringify! {
/// impl<C : ?Sized + Coroutine<Resume = ()>> coroutine for C
///
/// #[cfg(feature = "std")]
/// impl<C : ?Sized + Coroutine> Coroutine for Pin<Box<C>>
/// impl<C : ?Sized + Coroutine> Coroutine for Pin<&mut C>
/// # };
/// ```
pub