Skip to content

Commit 236d0c0

Browse files
bstriecatamorphism
authored andcommitted
---
yaml --- r: 33359 b: refs/heads/snap-stage3 c: 5e1d0ba h: refs/heads/master i: 33357: f61aa29 33355: 9b74046 33351: 0ca302a 33343: 9673bf2 v: v3
1 parent f6e266b commit 236d0c0

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: e94e82cb8ef0491667bc8041d370199aed838f2d
4+
refs/heads/snap-stage3: 5e1d0bab8075df5ce06543537296d7294440bd45
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/tutorial.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ let bloop = |well, oh: mygoodness| -> what_the { fail oh(well) };
15691569
~~~~
15701570

15711571
There are several forms of closure, each with its own role. The most
1572-
common, called a _stack closure_, has type `fn&` and can directly
1572+
common, called a _stack closure_, has type `&fn` and can directly
15731573
access local variables in the enclosing scope.
15741574

15751575
~~~~
@@ -1591,7 +1591,7 @@ pervasively in Rust code.
15911591
When you need to store a closure in a data structure, a stack closure
15921592
will not do, since the compiler will refuse to let you store it. For
15931593
this purpose, Rust provides a type of closure that has an arbitrary
1594-
lifetime, written `fn@` (boxed closure, analogous to the `@` pointer
1594+
lifetime, written `@fn` (boxed closure, analogous to the `@` pointer
15951595
type described earlier). This type of closure *is* first-class.
15961596

15971597
A managed closure does not directly access its environment, but merely
@@ -1604,8 +1604,9 @@ returns it from a function, and then calls it:
16041604

16051605
~~~~
16061606
# extern mod std;
1607-
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
1608-
return fn@(s: ~str) -> ~str { s + suffix };
1607+
fn mk_appender(suffix: ~str) -> @fn(~str) -> ~str {
1608+
// The compiler knows that we intend this closure to be of type @fn
1609+
return |s| s + suffix;
16091610
}
16101611
16111612
fn main() {
@@ -1614,22 +1615,9 @@ fn main() {
16141615
}
16151616
~~~~
16161617

1617-
This example uses the long closure syntax, `fn@(s: ~str) ...`. Using
1618-
this syntax makes it explicit that we are declaring a boxed
1619-
closure. In practice, boxed closures are usually defined with the
1620-
short closure syntax introduced earlier, in which case the compiler
1621-
infers the type of closure. Thus our managed closure example could
1622-
also be written:
1623-
1624-
~~~~
1625-
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
1626-
return |s| s + suffix;
1627-
}
1628-
~~~~
1629-
16301618
## Owned closures
16311619

1632-
Owned closures, written `fn~` in analogy to the `~` pointer type,
1620+
Owned closures, written `~fn` in analogy to the `~` pointer type,
16331621
hold on to things that can safely be sent between
16341622
processes. They copy the values they close over, much like managed
16351623
closures, but they also own them: that is, no other code can access
@@ -1649,12 +1637,10 @@ callers may pass any kind of closure.
16491637

16501638
~~~~
16511639
fn call_twice(f: fn()) { f(); f(); }
1652-
call_twice(|| { "I am an inferred stack closure"; } );
1653-
call_twice(fn&() { "I am also a stack closure"; } );
1654-
call_twice(fn@() { "I am a managed closure"; });
1655-
call_twice(fn~() { "I am an owned closure"; });
1656-
fn bare_function() { "I am a plain function"; }
1657-
call_twice(bare_function);
1640+
let closure = || { "I'm a closure, and it doesn't matter what type I am"; };
1641+
fn function() { "I'm a normal function"; }
1642+
call_twice(closure);
1643+
call_twice(function);
16581644
~~~~
16591645

16601646
> ***Note:*** Both the syntax and the semantics will be changing
@@ -1715,7 +1701,7 @@ parentheses, where it looks more like a typical block of
17151701
code.
17161702

17171703
`do` is a convenient way to create tasks with the `task::spawn`
1718-
function. `spawn` has the signature `spawn(fn: fn~())`. In other
1704+
function. `spawn` has the signature `spawn(fn: ~fn())`. In other
17191705
words, it is a function that takes an owned closure that takes no
17201706
arguments.
17211707

0 commit comments

Comments
 (0)