From e22ceea1a751f7a66277c323fc39c05832f59214 Mon Sep 17 00:00:00 2001 From: "Michael F. Lamb" Date: Wed, 6 Jan 2016 15:46:58 -0800 Subject: [PATCH] Explain surprising new syntax appearing in example code In a straight-through read of "Syntax and Semantics," the first time we meet a generic, and the first time we meet a vector, is when a Vec shows up in this example. I'm not sure that I could argue that the whole section should appear later in the book than the ones on vectors and generics, so instead just give the reader a brief introduction to both and a promise to follow up later. --- src/doc/book/ownership.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/doc/book/ownership.md b/src/doc/book/ownership.md index 17b263ef00ab..0a13d813f748 100644 --- a/src/doc/book/ownership.md +++ b/src/doc/book/ownership.md @@ -51,15 +51,24 @@ fn foo() { } ``` -When `v` comes into scope, a new [`Vec`][vect] is created. In this case, the -vector also allocates space on [the heap][heap], for the three elements. When -`v` goes out of scope at the end of `foo()`, Rust will clean up everything -related to the vector, even the heap-allocated memory. This happens -deterministically, at the end of the scope. +When `v` comes into scope, a new [vector][] is created, and it allocates space +on the heap for each of its elements. When `v` goes out of scope at the end of +`foo()`, Rust will clean up everything related to the vector, even the +heap-allocated memory. This happens deterministically, at the end of the scope. -[vect]: ../std/vec/struct.Vec.html +We'll cover [vectors][vector] in detail later in this chapter; we only use them +here as an example of a type that allocates space on the heap at runtime. They +behave like [arrays][], except their size may change by `push()`ing more +elements onto them. + +Vectors have a [generic type][generics] `Vec`, so in this example `v` will have type +`Vec`. We'll cover generics in detail later in this chapter. + +[arrays]: primitive-types.html#arrays +[vector]: vectors.html [heap]: the-stack-and-the-heap.html [bindings]: variable-bindings.html +[generics]: generics.html # Move semantics