Skip to content

Commit c8cd67d

Browse files
committed
Announce major Generator -> Coroutine rename
1 parent 31e59c7 commit c8cd67d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
layout: post
3+
title: Generators are dead, long live coroutines, generators are back
4+
author: oli-obk
5+
---
6+
7+
We have renamed the unstable `Generator` trait to `Coroutine` and adjusted all terminology accordingly.
8+
If you want to see all 3800 modified lines of code, you can find the PR [here](https://github.com/rust-lang/rust/pull/116958).
9+
10+
Our `Generator` trait was effectively a coroutine already, so this change was long overdue.
11+
All nightly users using the `Generator` trait must now update their code to refer to the new feature gate and trait names.
12+
13+
## What is the difference?
14+
15+
A generator is just a convenient way to write `Iterator` implementations.
16+
This means it's a coroutine that has no arguments and no return type.
17+
Instead when it returns, that means iteration is over, and the `Iterator::next` method returns `None`.
18+
19+
## Coming full circle
20+
21+
This change is directly motivated for *reintroducing* generators, this time with simpler (`async`/`await` style)
22+
syntax for creating `Iterator`s. Some discussion about this can be found in the [`gen fn` rfc](https://github.com/rust-lang/rfcs/pull/3513).
23+
24+
Of course such a massive change would be incomplete without the PR to immediately reintroduce a new concept with the name that was just removed,
25+
so [here](https://github.com/rust-lang/rust/pull/116447) you can see the MVP for `gen` blocks that has very weird diagnostics and may panic on you if you poke it too much.

0 commit comments

Comments
 (0)