Skip to content

Guide: Clarify that assigning/comparing different tuple types doesn't work #17836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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