Skip to content

Commit 8733b8b

Browse files
committed
examples added for element access
1 parent 05c5b5f commit 8733b8b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/libstd/tuple.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//!
1616
//! Indexing starts from zero, so `0` returns first value, `1`
1717
//! returns second value, and so on. In general, a tuple with _S_
18-
//! elements provides aforementioned fields from `0` to `S-1`
18+
//! elements provides aforementioned fields from `0` to `S-1`.
1919
//!
2020
//! If every type inside a tuple implements one of the following
2121
//! traits, then a tuple itself also implements it.
@@ -28,6 +28,17 @@
2828
//! * `Default`
2929
//!
3030
//! # Examples
31+
//!
32+
//! Accessing elements of a tuple at specified indices:
33+
//!
34+
//! ```
35+
//! let x = ("colorless", "green", "ideas", "sleep", "furiously");
36+
//! assert_eq!(x.3, "sleep");
37+
//!
38+
//! let v = (3i, 3i);
39+
//! let u = (1i, -5i);
40+
//! assert_eq!(v.0 * u.0 + v.1 * u.1, -12i);
41+
//! ```
3142
//!
3243
//! Using traits implemented for tuples:
3344
//!

0 commit comments

Comments
 (0)