Skip to content

Commit 474da41

Browse files
bstriecatamorphism
authored andcommitted
---
yaml --- r: 34778 b: refs/heads/master c: 5e1d0ba h: refs/heads/master v: v3
1 parent adb2b88 commit 474da41

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,5 +1,5 @@
11
---
2-
refs/heads/master: e94e82cb8ef0491667bc8041d370199aed838f2d
2+
refs/heads/master: 5e1d0bab8075df5ce06543537296d7294440bd45
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024

trunk/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)