Replace all uses of generator
in markdown documentation with coroutine
This commit is contained in:
parent
6fa47e15e7
commit
258af95a60
@ -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;
|
||||
};
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ The tracking issue for this feature is: [#87417]
|
||||
|
||||
------------------------
|
||||
|
||||
Allows using the `#[track_caller]` attribute on closures and generators.
|
||||
Calls made to the closure or generator will have caller information
|
||||
Allows using the `#[track_caller]` attribute on closures and coroutines.
|
||||
Calls made to the closure or coroutine will have caller information
|
||||
available through `std::panic::Location::caller()`, just like using
|
||||
`#[track_caller]` on a function.
|
||||
|
@ -5,31 +5,31 @@ each one organized by a "feature flag." That is, when using an unstable
|
||||
feature of Rust, you must use a flag, like this:
|
||||
|
||||
```rust
|
||||
#![feature(generators, generator_trait)]
|
||||
#![feature(coroutines, coroutine_trait)]
|
||||
|
||||
use std::ops::{Generator, GeneratorState};
|
||||
use std::ops::{Coroutine, CoroutineState};
|
||||
use std::pin::Pin;
|
||||
|
||||
fn main() {
|
||||
let mut generator = || {
|
||||
let mut coroutine = || {
|
||||
yield 1;
|
||||
return "foo"
|
||||
};
|
||||
|
||||
match Pin::new(&mut generator).resume(()) {
|
||||
GeneratorState::Yielded(1) => {}
|
||||
match Pin::new(&mut coroutine).resume(()) {
|
||||
CoroutineState::Yielded(1) => {}
|
||||
_ => panic!("unexpected value from resume"),
|
||||
}
|
||||
match Pin::new(&mut generator).resume(()) {
|
||||
GeneratorState::Complete("foo") => {}
|
||||
match Pin::new(&mut coroutine).resume(()) {
|
||||
CoroutineState::Complete("foo") => {}
|
||||
_ => panic!("unexpected value from resume"),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `generators` feature [has a chapter][generators] describing how to use it.
|
||||
The `coroutines` feature [has a chapter][coroutines] describing how to use it.
|
||||
|
||||
[generators]: language-features/generators.md
|
||||
[coroutines]: language-features/coroutines.md
|
||||
|
||||
Because this documentation relates to unstable features, we make no guarantees
|
||||
that what is contained here is accurate or up to date. It's developed on a
|
||||
|
@ -1,37 +1,37 @@
|
||||
LL| |#![feature(generators, generator_trait)]
|
||||
LL| |#![feature(coroutines, coroutine_trait)]
|
||||
LL| |#![allow(unused_assignments)]
|
||||
LL| |
|
||||
LL| |use std::ops::{Generator, GeneratorState};
|
||||
LL| |use std::ops::{Coroutine, CoroutineState};
|
||||
LL| |use std::pin::Pin;
|
||||
LL| |
|
||||
LL| 1|fn main() {
|
||||
LL| 1| let mut generator = || {
|
||||
LL| 1| let mut coroutine = || {
|
||||
LL| 1| yield 1;
|
||||
LL| 1| return "foo";
|
||||
LL| 1| };
|
||||
LL| |
|
||||
LL| 1| match Pin::new(&mut generator).resume(()) {
|
||||
LL| 1| GeneratorState::Yielded(1) => {}
|
||||
LL| 1| match Pin::new(&mut coroutine).resume(()) {
|
||||
LL| 1| CoroutineState::Yielded(1) => {}
|
||||
LL| 0| _ => panic!("unexpected value from resume"),
|
||||
LL| | }
|
||||
LL| 1| match Pin::new(&mut generator).resume(()) {
|
||||
LL| 1| GeneratorState::Complete("foo") => {}
|
||||
LL| 1| match Pin::new(&mut coroutine).resume(()) {
|
||||
LL| 1| CoroutineState::Complete("foo") => {}
|
||||
LL| 0| _ => panic!("unexpected value from resume"),
|
||||
LL| | }
|
||||
LL| |
|
||||
LL| 1| let mut generator = || {
|
||||
LL| 1| let mut coroutine = || {
|
||||
LL| 1| yield 1;
|
||||
LL| 1| yield 2;
|
||||
LL| 0| yield 3;
|
||||
LL| 0| return "foo";
|
||||
LL| 0| };
|
||||
LL| |
|
||||
LL| 1| match Pin::new(&mut generator).resume(()) {
|
||||
LL| 1| GeneratorState::Yielded(1) => {}
|
||||
LL| 1| match Pin::new(&mut coroutine).resume(()) {
|
||||
LL| 1| CoroutineState::Yielded(1) => {}
|
||||
LL| 0| _ => panic!("unexpected value from resume"),
|
||||
LL| | }
|
||||
LL| 1| match Pin::new(&mut generator).resume(()) {
|
||||
LL| 1| GeneratorState::Yielded(2) => {}
|
||||
LL| 1| match Pin::new(&mut coroutine).resume(()) {
|
||||
LL| 1| CoroutineState::Yielded(2) => {}
|
||||
LL| 0| _ => panic!("unexpected value from resume"),
|
||||
LL| | }
|
||||
LL| 1|}
|
||||
|
Loading…
x
Reference in New Issue
Block a user