@@ -216,6 +216,18 @@ In systems programming languages, strings are a bit more complex than in other
216216languages. For now, just read ` &str ` as a * string slice* , and we’ll learn more
217217soon.
218218
219+ You can assign one tuple into another, if they have the same contained types
220+ and [ arity] . Tuples have the same arity when they have the same length.
221+
222+ [ arity ] : glossary.html#arity
223+
224+ ``` rust
225+ let mut x = (1 , 2 ); // x: (i32, i32)
226+ let y = (2 , 3 ); // y: (i32, i32)
227+
228+ x = y ;
229+ ```
230+
219231You can access the fields in a tuple through a * destructuring let* . Here’s
220232an example:
221233
@@ -235,20 +247,24 @@ or "breaks up," the tuple, and assigns the bits to three bindings.
235247
236248This pattern is very powerful, and we’ll see it repeated more later.
237249
238- There are also a few things you can do with a tuple as a whole, without
239- destructuring. You can assign one tuple into another, if they have the same
240- contained types and [ arity] . Tuples have the same arity when they have the same
241- length.
250+ ## Tuple Indexing
251+
252+ You can also access fields of a tuple with indexing syntax:
242253
243- [ arity ] : glossary.html#arity
244254
245255``` rust
246- let mut x = (1 , 2 ); // x: (i32, i32)
247- let y = (2 , 3 ); // y: (i32, i32)
256+ let tuple = (1 , 2 , 3 );
248257
249- x = y ;
258+ let x = tuple . 0 ;
259+ let y = tuple . 1 ;
260+ let z = tuple . 2 ;
261+
262+ println! (" x is {}" , x );
250263```
251264
265+ Like array indexing, it starts at zero, but unlike array indexing, it uses a
266+ ` . ` , rather than ` [] ` s.
267+
252268You can find more documentation for tuples [ in the standard library
253269documentation] [ tuple ] .
254270
0 commit comments