diff --git a/book/src/chapter_3.md b/book/src/chapter_3.md index bc7cae67..ef9f8bb3 100644 --- a/book/src/chapter_3.md +++ b/book/src/chapter_3.md @@ -83,7 +83,7 @@ There's a fair amount of syntax that we haven't encountered before here, so lets 2. It *returns* a `Vec`. `Vec` is a Rust *Vector* (if you're familiar with C++, it's pretty much exactly the same as a C++ `std::vector`). A vector is like an *array* (see [this Rust by Example chapter](https://doc.rust-lang.org/rust-by-example/primitives/array.html)), which lets you put a bunch of data into a list and access each element. Unlike an *array*, a `Vec` doesn't have a size limit - and the size can change while the program runs. So you can `push` (add) new items, and `remove` them as you go. [Rust by Example has a great chapter on Vectors](https://doc.rust-lang.org/rust-by-example/std/vec.html); it's a good idea to learn about them - they are used *everywhere*. 3. `let mut map = vec![TileType::Floor; 80*50];` is a confusing looking statement! Lets break it down: 1. `let mut map` is saying "make a new variable" (`let`), "let me change it" (`mut`) and call it "map". - 2. `vec!` is a *macro*, another one build into the Rust standard library. The exclamation mark is Rust's way of saying "this is a procedural macro" (as opposed to a derive macro, like we've seen before). Procedural macros run like a function - they define a *procedure*, they just greatly reduce your typing. + 2. `vec!` is a *macro*, another one built into the Rust standard library. The exclamation mark is Rust's way of saying "this is a procedural macro" (as opposed to a derive macro, like we've seen before). Procedural macros run like a function - they define a *procedure*, they just greatly reduce your typing. 3. The `vec!` macro takes its parameters in square brackets. 4. The first parameter is the *value* for each element of the new vector. In this case, we're setting every entry we create to be a `Floor` (from the `TileType` enumeration). 5. The second parameter is how many tiles we should create. They will all be set to the value we set above. In this case, our map is 80x50 tiles (4,000 tiles - but we'll let the compiler do the math for us!). So we need to make 4,000 tiles.