Skip to content

Add a couple of examples on the generator section of the book #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2021

Conversation

spastorino
Copy link
Member

@spastorino spastorino commented Mar 26, 2021

The examples may be wrong or probably could be made better but I guess having some examples here would to better understand these concepts.

@@ -34,6 +34,18 @@ Of these types, only upvars and resume/yield/return are stored directly in `Gene
the generator by virtue of sharing the same `GeneratorId`. It is only used when determining
auto trait impls, where it is considered a 'constituent type'.

For example:

```rust
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- rust
+ rust,ignore 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, probably make a comment that this isn't a "real" syntax at the moment.


```rust
fn gen() -> Bar {
let a = yield 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, let's make this 0usize.

```rust
fn gen() -> Bar {
let a = yield 0;
return use(a);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a fn use(_: usize) -> Bar {} for clarity

@jackh726
Copy link
Member

r=me on changes and green CI

@bors delegate+

@bors
Copy link
Contributor

bors commented Mar 27, 2021

✌️ @spastorino can now approve this pull request

@jackh726
Copy link
Member

(I also just realized that @spastorino already has r+ rights)

@spastorino spastorino force-pushed the add-examples-about-generators branch from d0f2186 to 255db5a Compare March 27, 2021 22:07
@spastorino
Copy link
Member Author

@bors r=jackh726

@bors
Copy link
Contributor

bors commented Mar 27, 2021

📌 Commit 255db5a has been approved by jackh726

@bors
Copy link
Contributor

bors commented Mar 27, 2021

⌛ Testing commit 255db5a with merge 954d1c5...

@bors
Copy link
Contributor

bors commented Mar 27, 2021

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 954d1c5 to master...

@bors bors merged commit 954d1c5 into rust-lang:master Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants