about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorDirk Gadsden <dirk@esherido.com>2016-02-14 17:00:46 -0800
committerManish Goregaokar <manishsmail@gmail.com>2016-02-16 04:10:30 +0530
commitf2bea1cb7096e5e837a6fb2d2d72d4b0e4ced507 (patch)
tree9dd9d8ae9e894becb80ba73fe629cc866f37e7cf /src/doc
parent17691af38d68755ffa0ff1d5752bdfbe57264abd (diff)
downloadrust-f2bea1cb7096e5e837a6fb2d2d72d4b0e4ced507.tar.gz
rust-f2bea1cb7096e5e837a6fb2d2d72d4b0e4ced507.zip
Clarify contiguous memory array structure of vectors in documentation
Closes #31554.

Contributes to #29380.
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/book/vectors.md11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/doc/book/vectors.md b/src/doc/book/vectors.md
index b09735c3fee..f5a543d75b1 100644
--- a/src/doc/book/vectors.md
+++ b/src/doc/book/vectors.md
@@ -11,8 +11,8 @@ let v = vec![1, 2, 3, 4, 5]; // v: Vec<i32>
 ```
 
 (Notice that unlike the `println!` macro we’ve used in the past, we use square
-brackets `[]` with `vec!` macro. Rust allows you to use either in either situation,
-this is just convention.)
+brackets `[]` with `vec!` macro. Rust allows you to use either in either
+situation, this is just convention.)
 
 There’s an alternate form of `vec!` for repeating an initial value:
 
@@ -20,6 +20,12 @@ There’s an alternate form of `vec!` for repeating an initial value:
 let v = vec![0; 10]; // ten zeroes
 ```
 
+Vectors store their contents as contiguous arrays of `T` on the heap. This means
+that they must be able to know the size of `T` at compile time (that is, how
+many bytes are needed to store a `T`?). The size of some things can't be known
+at compile time. For these you'll have to store a pointer to that thing:
+thankfully, the [`Box`][box] type works perfectly for this.
+
 ## Accessing elements
 
 To get the value at a particular index in the vector, we use `[]`s:
@@ -113,6 +119,7 @@ Vectors have many more useful methods, which you can read about in [their
 API documentation][vec].
 
 [vec]: ../std/vec/index.html
+[box]: ../std/boxed/index.html
 [generic]: generics.html
 [panic]: concurrency.html#panics
 [get]: http://doc.rust-lang.org/std/vec/struct.Vec.html#method.get