Skip to content

Commit 078eb57

Browse files
bstriecatamorphism
authored andcommitted
---
yaml --- r: 38636 b: refs/heads/incoming c: 5e1d0ba h: refs/heads/master v: v3
1 parent 2da5f6c commit 078eb57

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
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: e94e82cb8ef0491667bc8041d370199aed838f2d
9+
refs/heads/incoming: 5e1d0bab8075df5ce06543537296d7294440bd45
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/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)