Replace all uses of generator
in markdown documentation with coroutine
This commit is contained in:
parent
6fa47e15e7
commit
258af95a60
8 changed files with 52 additions and 52 deletions
|
@ -1,10 +1,10 @@
|
|||
This error occurs because a borrow in a generator persists across a
|
||||
This error occurs because a borrow in a coroutine persists across a
|
||||
yield point.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0626
|
||||
# #![feature(generators, generator_trait, pin)]
|
||||
# #![feature(coroutines, coroutine_trait, pin)]
|
||||
# use std::ops::Coroutine;
|
||||
# use std::pin::Pin;
|
||||
let mut b = || {
|
||||
|
@ -23,7 +23,7 @@ resolve the previous example by removing the borrow and just storing
|
|||
the integer by value:
|
||||
|
||||
```
|
||||
# #![feature(generators, generator_trait, pin)]
|
||||
# #![feature(coroutines, coroutine_trait, pin)]
|
||||
# use std::ops::Coroutine;
|
||||
# use std::pin::Pin;
|
||||
let mut b = || {
|
||||
|
@ -41,7 +41,7 @@ in those cases, something like the `Rc` or `Arc` types may be useful.
|
|||
This error also frequently arises with iteration:
|
||||
|
||||
```compile_fail,E0626
|
||||
# #![feature(generators, generator_trait, pin)]
|
||||
# #![feature(coroutines, coroutine_trait, pin)]
|
||||
# use std::ops::Coroutine;
|
||||
# use std::pin::Pin;
|
||||
let mut b = || {
|
||||
|
@ -57,7 +57,7 @@ Such cases can sometimes be resolved by iterating "by value" (or using
|
|||
`into_iter()`) to avoid borrowing:
|
||||
|
||||
```
|
||||
# #![feature(generators, generator_trait, pin)]
|
||||
# #![feature(coroutines, coroutine_trait, pin)]
|
||||
# use std::ops::Coroutine;
|
||||
# use std::pin::Pin;
|
||||
let mut b = || {
|
||||
|
@ -72,7 +72,7 @@ Pin::new(&mut b).resume(());
|
|||
If taking ownership is not an option, using indices can work too:
|
||||
|
||||
```
|
||||
# #![feature(generators, generator_trait, pin)]
|
||||
# #![feature(coroutines, coroutine_trait, pin)]
|
||||
# use std::ops::Coroutine;
|
||||
# use std::pin::Pin;
|
||||
let mut b = || {
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
A yield expression was used outside of the generator literal.
|
||||
A yield expression was used outside of the coroutine literal.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0627
|
||||
#![feature(generators, generator_trait)]
|
||||
#![feature(coroutines, coroutine_trait)]
|
||||
|
||||
fn fake_generator() -> &'static str {
|
||||
fn fake_coroutine() -> &'static str {
|
||||
yield 1;
|
||||
return "foo"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut generator = fake_generator;
|
||||
let mut coroutine = fake_coroutine;
|
||||
}
|
||||
```
|
||||
|
||||
The error occurs because keyword `yield` can only be used inside the generator
|
||||
literal. This can be fixed by constructing the generator correctly.
|
||||
The error occurs because keyword `yield` can only be used inside the coroutine
|
||||
literal. This can be fixed by constructing the coroutine correctly.
|
||||
|
||||
```
|
||||
#![feature(generators, generator_trait)]
|
||||
#![feature(coroutines, coroutine_trait)]
|
||||
|
||||
fn main() {
|
||||
let mut generator = || {
|
||||
let mut coroutine = || {
|
||||
yield 1;
|
||||
return "foo"
|
||||
};
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
More than one parameter was used for a generator.
|
||||
More than one parameter was used for a coroutine.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0628
|
||||
#![feature(generators, generator_trait)]
|
||||
#![feature(coroutines, coroutine_trait)]
|
||||
|
||||
fn main() {
|
||||
let generator = |a: i32, b: i32| {
|
||||
// error: too many parameters for a generator
|
||||
let coroutine = |a: i32, b: i32| {
|
||||
// error: too many parameters for a coroutine
|
||||
// Allowed only 0 or 1 parameter
|
||||
yield a;
|
||||
};
|
||||
|
@ -15,15 +15,15 @@ fn main() {
|
|||
```
|
||||
|
||||
At present, it is not permitted to pass more than one explicit
|
||||
parameter for a generator.This can be fixed by using
|
||||
at most 1 parameter for the generator. For example, we might resolve
|
||||
parameter for a coroutine.This can be fixed by using
|
||||
at most 1 parameter for the coroutine. For example, we might resolve
|
||||
the previous example by passing only one parameter.
|
||||
|
||||
```
|
||||
#![feature(generators, generator_trait)]
|
||||
#![feature(coroutines, coroutine_trait)]
|
||||
|
||||
fn main() {
|
||||
let generator = |a: i32| {
|
||||
let coroutine = |a: i32| {
|
||||
yield a;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#### Note: this error code is no longer emitted by the compiler.
|
||||
|
||||
When using generators (or async) all type variables must be bound so a
|
||||
generator can be constructed.
|
||||
When using coroutines (or async) all type variables must be bound so a
|
||||
coroutine can be constructed.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
|
@ -15,7 +15,7 @@ async fn foo() {
|
|||
|
||||
In the above example `T` is unknowable by the compiler.
|
||||
To fix this you must bind `T` to a concrete type such as `String`
|
||||
so that a generator can then be constructed:
|
||||
so that a coroutine can then be constructed:
|
||||
|
||||
```edition2018
|
||||
async fn bar<T>() -> () {}
|
||||
|
|
|
@ -3,10 +3,10 @@ A `yield` clause was used in an `async` context.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0727,edition2018
|
||||
#![feature(generators)]
|
||||
#![feature(coroutines)]
|
||||
|
||||
fn main() {
|
||||
let generator = || {
|
||||
let coroutine = || {
|
||||
async {
|
||||
yield;
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ which is not yet supported.
|
|||
To fix this error, you have to move `yield` out of the `async` block:
|
||||
|
||||
```edition2018
|
||||
#![feature(generators)]
|
||||
#![feature(coroutines)]
|
||||
|
||||
fn main() {
|
||||
let generator = || {
|
||||
let coroutine = || {
|
||||
yield;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue