@@ -1569,7 +1569,7 @@ let bloop = |well, oh: mygoodness| -> what_the { fail oh(well) };
1569
1569
~~~~
1570
1570
1571
1571
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
1573
1573
access local variables in the enclosing scope.
1574
1574
1575
1575
~~~~
@@ -1591,7 +1591,7 @@ pervasively in Rust code.
1591
1591
When you need to store a closure in a data structure, a stack closure
1592
1592
will not do, since the compiler will refuse to let you store it. For
1593
1593
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
1595
1595
type described earlier). This type of closure * is* first-class.
1596
1596
1597
1597
A managed closure does not directly access its environment, but merely
@@ -1604,8 +1604,9 @@ returns it from a function, and then calls it:
1604
1604
1605
1605
~~~~
1606
1606
# 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;
1609
1610
}
1610
1611
1611
1612
fn main() {
@@ -1614,22 +1615,9 @@ fn main() {
1614
1615
}
1615
1616
~~~~
1616
1617
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
-
1630
1618
## Owned closures
1631
1619
1632
- Owned closures, written ` fn~ ` in analogy to the ` ~ ` pointer type,
1620
+ Owned closures, written ` ~fn ` in analogy to the ` ~ ` pointer type,
1633
1621
hold on to things that can safely be sent between
1634
1622
processes. They copy the values they close over, much like managed
1635
1623
closures, but they also own them: that is, no other code can access
@@ -1649,12 +1637,10 @@ callers may pass any kind of closure.
1649
1637
1650
1638
~~~~
1651
1639
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);
1658
1644
~~~~
1659
1645
1660
1646
> *** Note:*** Both the syntax and the semantics will be changing
@@ -1715,7 +1701,7 @@ parentheses, where it looks more like a typical block of
1715
1701
code.
1716
1702
1717
1703
` 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
1719
1705
words, it is a function that takes an owned closure that takes no
1720
1706
arguments.
1721
1707
0 commit comments