Skip to content

Updated "while let" example. #30059

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 3 commits into from
Nov 29, 2015
Merged

Updated "while let" example. #30059

merged 3 commits into from
Nov 29, 2015

Conversation

androm3da
Copy link
Contributor

No description provided.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@androm3da
Copy link
Contributor Author

The text seemed confusing as-is, since it appeared to have no halting condition (are we iterating over "option"?).

@steveklabnik
Copy link
Member

@bors: r+ rollup

I agree, this is nicer, thanks.

@bors
Copy link
Collaborator

bors commented Nov 25, 2015

📌 Commit b1c5c26 has been approved by steveklabnik

@brson
Copy link
Contributor

brson commented Nov 25, 2015

This explanation implies that while let is tied to iterators, which it is not.

@androm3da
Copy link
Contributor Author

Can you recommend an improvement, or does this mean you think it should stay as-is?

@androm3da
Copy link
Contributor Author

Proposal: I should restore the original prose and leave the example code as shown.

@steveklabnik
Copy link
Member

@brson: ahhh, shucks, reading this, my brain said "while uses an iterator, sure", but while != while let.

@androm3da how about changing it so that the whole example is visible, and remove the temporary?

@steveklabnik
Copy link
Member

@bors: r- for now

@androm3da
Copy link
Contributor Author

@steveklabnik "The temporary" refers to "vec![1, 3, 5, 7, 9, ]"? (sorry, still a bit of a rust newb)

@steveklabnik
Copy link
Member

It's all good! I myself made a mistake: when thinking about it, i was thinking this:

let v = vec![1, 3, 5, 7, 9];
while let Some(x) = v.iter() {
    println!("{}", x);
}

but that doesn't work. This should be fine:

let v = vec![1, 3, 5, 7, 9];
let mut iter = v.iter();
while let Some(x) = iter.next() {
    println!("{}", x);
}

# let option: Option<i32> = None;
while let Some(x) = option {
let v: vec![1, 3, 5, 7, 11, ];
let mut iter: v.iter();
Copy link
Member

Choose a reason for hiding this comment

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

should be =, not : on these two lines.

But, why not show off something else than iterators since that's a good while let speciality? For example looping over the result of v.pop().

Copy link
Member

Choose a reason for hiding this comment

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

let mut v = vec![1, 3, 5, 7, 11];
while let Some(x) = v.pop() {
    println!("{}", x);
}

@bluss
Copy link
Member

bluss commented Nov 29, 2015

Nice! Thank you

@bors r+ 797a0bd

@bluss
Copy link
Member

bluss commented Nov 29, 2015

(A comment on the PR is needed to notify people involved, a pushed commit does not notify, so that's the reason for the two day delay).

Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 29, 2015
@bors
Copy link
Collaborator

bors commented Nov 29, 2015

⌛ Testing commit 797a0bd with merge 3db9bee...

bors added a commit that referenced this pull request Nov 29, 2015
@bors bors merged commit 797a0bd into rust-lang:master Nov 29, 2015
bors added a commit that referenced this pull request Nov 30, 2015
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.

6 participants