about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2015-04-16 16:12:47 -0400
committerSteve Klabnik <steve@steveklabnik.com>2015-04-16 23:50:16 -0400
commit525a1462b50ca12a3889751652bc8993e7f0b540 (patch)
tree1743a4602fdc1e9b11d23a266c5253d047231eaa
parentdc4554a9b347aaaef87a0093375657e7d5176a34 (diff)
downloadrust-525a1462b50ca12a3889751652bc8993e7f0b540.tar.gz
rust-525a1462b50ca12a3889751652bc8993e7f0b540.zip
Descripe tuple indexing in TRPL
FIxes #23962
-rw-r--r--src/doc/trpl/primitive-types.md32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/doc/trpl/primitive-types.md b/src/doc/trpl/primitive-types.md
index fcbe2b2f8bf..811080cd509 100644
--- a/src/doc/trpl/primitive-types.md
+++ b/src/doc/trpl/primitive-types.md
@@ -216,6 +216,18 @@ In systems programming languages, strings are a bit more complex than in other
 languages. For now, just read `&str` as a *string slice*, and we’ll learn more
 soon.
 
+You can assign one tuple into another, if they have the same contained types
+and [arity]. Tuples have the same arity when they have the same length.
+
+[arity]: glossary.html#arity
+
+```rust
+let mut x = (1, 2); // x: (i32, i32)
+let y = (2, 3); // y: (i32, i32)
+
+x = y;
+```
+
 You can access the fields in a tuple through a *destructuring let*. Here’s
 an example:
 
@@ -235,20 +247,24 @@ or "breaks up," the tuple, and assigns the bits to three bindings.
 
 This pattern is very powerful, and we’ll see it repeated more later.
 
-There are also a few things you can do with a tuple as a whole, without
-destructuring. You can assign one tuple into another, if they have the same
-contained types and [arity]. Tuples have the same arity when they have the same
-length.
+## Tuple Indexing
+
+You can also access fields of a tuple with indexing syntax:
 
-[arity]: glossary.html#arity
 
 ```rust
-let mut x = (1, 2); // x: (i32, i32)
-let y = (2, 3); // y: (i32, i32)
+let tuple = (1, 2, 3);
 
-x = y;
+let x = tuple.0;
+let y = tuple.1;
+let z = tuple.2;
+
+println!("x is {}", x);
 ```
 
+Like array indexing, it starts at zero, but unlike array indexing, it uses a
+`.`, rather than `[]`s.
+
 You can find more documentation for tuples [in the standard library
 documentation][tuple].