I’ve been reading about the upcoming co-routines feature in C++17 and I’ve stumbled upon the following pdf presentation which explains implementation details which is a fairly recent version of the proposal.
Page 52 of that presentation makes an interesting observation - the same mechanism (the await keyword) can be used in a more general setting (quoting from that page):
await: unwraps a value from a container M*
return: puts a value back into a container M
Future: container of T, unwrapping strips temporal aspect
optional: container of T, unwrapping strips “not there aspect”
expected: container of T, unwrapping strips “or an error aspect”
std::future: unwrapping strips temporal and may have error aspects
The “expected” type reminded me of the Result type and made me think about RFC-243 - the (long) debate over this RFC was whether the proposed syntax can be replaced by a more general “do” notation as in Haskell but the problem with that is that it has poor interaction with procedural code (control flow, early returns).
Could co-routine syntax be useful in this context for Rust? could a co-routine replace the do-notation or the proposed catch block?