From eb0a451f65b9175e1c77d8ebb9d6940f059e8a42 Mon Sep 17 00:00:00 2001 From: David Koslow Date: Fri, 13 Jan 2023 18:42:51 -0500 Subject: [PATCH] typo: brackets -> parentheses typo: brackets -> parentheses --- book/src/chapter_2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/chapter_2.md b/book/src/chapter_2.md index 97b956df..f280c402 100644 --- a/book/src/chapter_2.md +++ b/book/src/chapter_2.md @@ -223,7 +223,7 @@ This line says `join` positions and renderables; like a database join, it only r The `join` function returns an *iterator*. [The Rust Book has a great section on iterators](https://doc.rust-lang.org/book/ch13-02-iterators.html). In C++, iterators provide a `begin`, `next` and `end` function - and you can move between elements in collections with them. Rust extends the same concept, only on steroids: just about anything can be made into an iterator if you put your mind to it. Iterators work very well with `for` loops - you can provide any iterator as the target in `for x in iterator` loops. The `0..10` we discussed earlier really is a *range* - and offers an *iterator* for Rust to navigate. -The other interesting thing here are the parentheses. In Rust, when you wrap variables in brackets you are making a *tuple*. These are just a collection of variables, grouped together - but without needing to go and make a structure just for this case. You can access them individually via numeric access (`mytuple.0`, `mytuple.1`, etc.) to get to each field, or you can *destructure* them. `(one, two) = (1, 2)` sets the variable `one` to `1`, and the variable `two` to `2`. That's what we're doing here: the `join` iterator is returning *tuples* containing a `Position` and a `Renderable` component as `.0` and `.1`. Since typing that is ugly and unclear, we *destructure* them into the named variables `pos` and `render`. This can be confusing at first, so if you are struggling I recommend [Rust By Example's section on Tuples](https://doc.rust-lang.org/rust-by-example/primitives/tuples.html). +The other interesting thing here are the parentheses. In Rust, when you wrap variables in parentheses you are making a *tuple*. These are just a collection of variables, grouped together - but without needing to go and make a structure just for this case. You can access them individually via numeric access (`mytuple.0`, `mytuple.1`, etc.) to get to each field, or you can *destructure* them. `(one, two) = (1, 2)` sets the variable `one` to `1`, and the variable `two` to `2`. That's what we're doing here: the `join` iterator is returning *tuples* containing a `Position` and a `Renderable` component as `.0` and `.1`. Since typing that is ugly and unclear, we *destructure* them into the named variables `pos` and `render`. This can be confusing at first, so if you are struggling I recommend [Rust By Example's section on Tuples](https://doc.rust-lang.org/rust-by-example/primitives/tuples.html). ```rust ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph);