Skip to content

Commit b3b55e7

Browse files
committed
---
yaml --- r: 35676 b: refs/heads/master c: 45e62d0 h: refs/heads/master v: v3
1 parent 876d62a commit b3b55e7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d098faa8555d48a9bc1de34542fc6d1dd5a2ab9c
2+
refs/heads/master: 45e62d0a144f336e2ad849c1bb7767a12f312643
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024

trunk/doc/tutorial.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,15 @@ assert 8 == line(5, 3, 1);
813813
assert () == oops(5, 3, 1);
814814
~~~~
815815

816+
As with `match` expressions and `let` bindings, function arguments support
817+
pattern destructuring. Like `let`, argument patterns must be irrefutable,
818+
as in this example that unpacks a tuple and returns it.
819+
820+
~~~
821+
fn first((value, _): (int, float)) -> int { value }
822+
~~~
823+
824+
816825
# The Rust memory model
817826

818827
At this junction, let's take a detour to explain the concepts involved
@@ -1576,6 +1585,21 @@ fn contains(v: &[int], elt: int) -> bool {
15761585
}
15771586
~~~~
15781587

1588+
Notice that, because `each` passes each value by borrowed pointer,
1589+
the iteratee needs to dereference it before using.
1590+
In these situations it can be convenient to lean on Rust's
1591+
argument patterns to bind `x` to the actual value, not the pointer.
1592+
1593+
~~~~
1594+
# use each = vec::each;
1595+
# fn contains(v: &[int], elt: int) -> bool {
1596+
for each(v) |&x| {
1597+
if (x == elt) { return true; }
1598+
}
1599+
# false
1600+
# }
1601+
~~~~
1602+
15791603
`for` syntax only works with stack closures.
15801604

15811605
> ***Note:*** This is, essentially, a special loop protocol:

0 commit comments

Comments
 (0)