-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Explained the difference between ownership iteration and reference iteration #32002
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (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. |
@@ -114,7 +114,30 @@ for i in v { | |||
println!("Take ownership of the vector and its element {}", i); | |||
} | |||
``` | |||
Note: You cannot use the vector again once you have iterated with ownership of the vector. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iterated by taking ownership of the vector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also, please put a newline above this line as well)
Thanks so much @srinivasreddy ! I like @Manishearth 's grammar suggestions, and I have some whitespace ones as well. We're good to go after that's fixed up! |
@steveklabnik Welcome!! @Manishearth Please review and merge |
} | ||
|
||
for i in &v { | ||
println!("This is a reference {}", i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this text match the previous
@Manishearth Done |
@bors r+ rollup |
📌 Commit 2dc723d has been approved by |
Thanks! |
@Manishearth I am new to travis. Do you see any reason for build failure? Could you please help me ? |
You can iterate the vector multiple times by taking a reference to the vector whilst iterating. | ||
For example, the following code does not compile. | ||
|
||
```rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to have rust,ignore
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Manishearth Done. Please issue auto merge
Ah, in this case the doctest failed. Rust code in documentation is compiled and run as a test, so your example of failing code should be annotated as mentioned above to skip this. |
⌛ Testing commit 2dc723d with merge 02c4cb5... |
💔 Test failed - auto-linux-64-opt |
@bors r+ rollup |
📌 Commit d2df551 has been approved by |
@Manishearth Please merge. Or could @bors automatically merge this? |
Yes. Bors will run tests on the CI and automatically merge if they pass, like last time. |
There's a queue (http://buildbot.rust-lang.org/homu/queue/rust), so it might take some time for your PR to get merged. |
…arth Issue here : rust-lang#31991
…arth Issue here : rust-lang#31991
Issue here : #31991