Skip to content

Commit

Permalink
Clarify that assigning/comparing different tuple types to one another…
Browse files Browse the repository at this point in the history
… won't compile
  • Loading branch information
isabelmu committed Oct 7, 2014
1 parent b5ba2f5 commit c211d13
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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:

Expand Down

1 comment on commit c211d13

@steveklabnik
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.