about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2016-03-04 14:17:28 -0500
committerSteve Klabnik <steve@steveklabnik.com>2016-03-04 14:17:28 -0500
commit55bc488db46c656c18c61c56de10446c3572b7d7 (patch)
treee72774a3b5c20c0b4763dd4363dc499ec055c394
parentc97524bef9e59a80875110b402b3fc8c139d4d64 (diff)
parentd2df5514c09aa0d9a648183b33b5b1ee1c6d0fa2 (diff)
downloadrust-55bc488db46c656c18c61c56de10446c3572b7d7.tar.gz
rust-55bc488db46c656c18c61c56de10446c3572b7d7.zip
Rollup merge of #32002 - srinivasreddy:vector_doc, r=Manishearth
Issue here : https://github.com/rust-lang/rust/issues/31991
-rw-r--r--src/doc/book/vectors.md30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/doc/book/vectors.md b/src/doc/book/vectors.md
index f5a543d75b1..ceb6b3c003e 100644
--- a/src/doc/book/vectors.md
+++ b/src/doc/book/vectors.md
@@ -115,6 +115,36 @@ for i in v {
 }
 ```
 
+Note: You cannot use the vector again once you have iterated by taking ownership of the vector.
+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,ignore
+let mut v = vec![1, 2, 3, 4, 5];
+
+for i in v {
+    println!("Take ownership of the vector and its element {}", i);
+}
+
+for i in v {
+    println!("Take ownership of the vector and its element {}", i);
+}
+```
+
+Whereas the following works perfectly,
+
+```rust
+let mut v = vec![1, 2, 3, 4, 5];
+
+for i in &v {
+    println!("This is a reference to {}", i);
+}
+
+for i in &v {
+    println!("This is a reference to {}", i);
+}
+```
+
 Vectors have many more useful methods, which you can read about in [their
 API documentation][vec].