From c211d132c38f06196e76c0b5536fb2ae6af4d521 Mon Sep 17 00:00:00 2001 From: Johannes Muenzel Date: Tue, 7 Oct 2014 01:22:58 -0400 Subject: [PATCH] Clarify that assigning/comparing different tuple types to one another won't compile --- src/doc/guide.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/doc/guide.md b/src/doc/guide.md index 871ceb21f6a..55f7cd02d55 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -914,12 +914,23 @@ 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. -The last thing to say about tuples is that they are only equivalent if -the arity, types, and values are all identical. +There 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 +arity and contained types. + +```rust +let mut x = (1i, 2i); +let y = (2i, 3i); + +x = y; +``` + +You can also check for equality with `==`. Again, this will only compile if the +tuples have the same type. ```rust let x = (1i, 2i, 3i); -let y = (2i, 3i, 4i); +let y = (2i, 2i, 4i); if x == y { println!("yes"); @@ -928,7 +939,7 @@ if x == y { } ``` -This will print `no`, as the values aren't equal. +This will print `no`, because some of the values aren't equal. One other use of tuples is to return multiple values from a function: