From 8733b8b19c510737faed35b83fdecc1c41a96a27 Mon Sep 17 00:00:00 2001 From: FakeKane Date: Mon, 5 Jan 2015 16:22:03 -0500 Subject: [PATCH] examples added for element access --- src/libstd/tuple.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index a12844f039e..0c8273abde4 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -15,7 +15,7 @@ //! //! Indexing starts from zero, so `0` returns first value, `1` //! returns second value, and so on. In general, a tuple with _S_ -//! elements provides aforementioned fields from `0` to `S-1` +//! elements provides aforementioned fields from `0` to `S-1`. //! //! If every type inside a tuple implements one of the following //! traits, then a tuple itself also implements it. @@ -28,6 +28,17 @@ //! * `Default` //! //! # Examples +//! +//! Accessing elements of a tuple at specified indices: +//! +//! ``` +//! let x = ("colorless", "green", "ideas", "sleep", "furiously"); +//! assert_eq!(x.3, "sleep"); +//! +//! let v = (3i, 3i); +//! let u = (1i, -5i); +//! assert_eq!(v.0 * u.0 + v.1 * u.1, -12i); +//! ``` //! //! Using traits implemented for tuples: //!