The Coroutine trait defines how to resume a coroutine and distinguish a yielded value from its final return. The compiler implements it for coroutine closures; understanding the interface helps with more complex uses. section 8.2
Listing 8.5 std::ops::Coroutine trait definition from Rust standard library
pub trait Coroutine<R = ()> { #1
type Yield; #2
type Return; #3
// Required method
fn resume(
self: Pin<&mut Self>, #4
arg: R
) -> CoroutineState<Self::Yield, Self::Return>;
}
The signature exposes the input type, yielded and returned types, and pinned resume method. section 8.2
Yield, then complete
A coroutine closure yields pi on its first resume and returns a string on its second. Matching CoroutineState distinguishes the two outcomes. section 8.2
