@@ -1559,11 +1559,11 @@ Type parameters can be specified for a trait to make it generic. These appear
1559
1559
after the trait name, using the same syntax used in [ generic
1560
1560
functions] ( #generic-functions ) .
1561
1561
1562
- ``` ignore
1562
+ ```
1563
1563
trait Seq<T> {
1564
1564
fn len(&self) -> uint;
1565
1565
fn elt_at(&self, n: uint) -> T;
1566
- fn iter(&self, |T| );
1566
+ fn iter<F> (&self, F) where F: Fn(T );
1567
1567
}
1568
1568
```
1569
1569
@@ -3217,8 +3217,8 @@ expression's captured environment.
3217
3217
In this example, we define a function ` ten_times ` that takes a higher-order
3218
3218
function argument, and call it with a lambda expression as an argument.
3219
3219
3220
- ``` ignore
3221
- fn ten_times(f: | int| ) {
3220
+ ```
3221
+ fn ten_times<F> (f: F) where F: Fn( int) {
3222
3222
let mut i = 0;
3223
3223
while i < 10 {
3224
3224
f(i);
@@ -3821,14 +3821,14 @@ or `extern`), a sequence of input types and an output type.
3821
3821
3822
3822
An example of a ` fn ` type:
3823
3823
3824
- ``` ignore
3824
+ ```
3825
3825
fn add(x: int, y: int) -> int {
3826
3826
return x + y;
3827
3827
}
3828
3828
3829
3829
let mut x = add(5,7);
3830
3830
3831
- type Binop<'a> = | int,int|: 'a -> int;
3831
+ type Binop = fn( int, int) -> int;
3832
3832
let bo: Binop = add;
3833
3833
x = bo(5,7);
3834
3834
```
@@ -3849,17 +3849,17 @@ The type of a closure mapping an input of type `A` to an output of type `B` is
3849
3849
3850
3850
An example of creating and calling a closure:
3851
3851
3852
- ``` ignore
3852
+ ``` rust
3853
3853
let captured_var = 10i ;
3854
3854
3855
- let closure_no_args = || println!("captured_var={}", captured_var);
3855
+ let closure_no_args = | & : | println! (" captured_var={}" , captured_var );
3856
3856
3857
- let closure_args = |arg: int| -> int {
3857
+ let closure_args = | & : arg : int | -> int {
3858
3858
println! (" captured_var={}, arg={}" , captured_var , arg );
3859
3859
arg // Note lack of semicolon after 'arg'
3860
3860
};
3861
3861
3862
- fn call_closure(c1: ||, c2: | int| -> int) {
3862
+ fn call_closure < F : Fn (), G : Fn ( int ) -> int >( c1 : F , c2 : G ) {
3863
3863
c1 ();
3864
3864
c2 (2 );
3865
3865
}
0 commit comments