ignore boxed closure doctests in the guide/reference

This commit is contained in:
Jorge Aparicio 2015-01-05 08:25:55 -05:00
parent a9ea4d0127
commit ab0c7af376
3 changed files with 16 additions and 16 deletions

View file

@ -536,7 +536,7 @@ optimizer to consider the result used and ensures it cannot remove the
computation entirely. This could be done for the example above by adjusting the
`b.iter` call to
```rust
```{rust,ignore}
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let b = X;
b.iter(|| {
// note lack of `;` (could also use an explicit `return`).
@ -548,7 +548,7 @@ Or, the other option is to call the generic `test::black_box` function, which
is an opaque "black box" to the optimizer and so forces it to consider any
argument as used.
```rust
```{rust,ignore}
extern crate test;
# fn main() {

View file

@ -4231,7 +4231,7 @@ arguments, really powerful things are possible.
Let's make a closure:
```{rust}
```{rust,ignore}
let add_one = |x| { 1 + x };
println!("The sum of 5 plus 1 is {}.", add_one(5));
@ -4243,7 +4243,7 @@ binding name and two parentheses, just like we would for a named function.
Let's compare syntax. The two are pretty close:
```{rust}
```{rust,ignore}
let add_one = |x: i32| -> i32 { 1 + x };
fn add_one (x: i32) -> i32 { 1 + x }
```
@ -4256,7 +4256,7 @@ There's one big difference between a closure and named functions, and it's in
the name: a closure "closes over its environment." What does that mean? It means
this:
```{rust}
```{rust,ignore}
fn main() {
let x = 5;
@ -4297,7 +4297,7 @@ now. We'll talk about them more in the "Threads" section of the guide.
Closures are most useful as an argument to another function. Here's an example:
```{rust}
```{rust,ignore}
fn twice(x: i32, f: |i32| -> i32) -> i32 {
f(x) + f(x)
}
@ -4311,14 +4311,14 @@ fn main() {
Let's break the example down, starting with `main`:
```{rust}
```{rust,ignore}
let square = |x: i32| { x * x };
```
We've seen this before. We make a closure that takes an integer, and returns
its square.
```{rust}
```{rust,ignore}
# fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) }
# let square = |x: i32| { x * x };
twice(5, square); // evaluates to 50
@ -4342,7 +4342,7 @@ though, and that function takes an `i32` and returns an `i32`. Notice
how the `|i32| -> i32` syntax looks a lot like our definition of `square`
above, if we added the return type in:
```{rust}
```{rust,ignore}
let square = |x: i32| -> i32 { x * x };
// |i32| -> i32
```
@ -4357,7 +4357,7 @@ Finally, `twice` returns an `i32` as well.
Okay, let's look at the body of `twice`:
```{rust}
```{rust,ignore}
fn twice(x: i32, f: |i32| -> i32) -> i32 {
f(x) + f(x)
}
@ -4375,7 +4375,7 @@ this technique a lot.
If we didn't want to give `square` a name, we could just define it inline.
This example is the same as the previous one:
```{rust}
```{rust,ignore}
fn twice(x: i32, f: |i32| -> i32) -> i32 {
f(x) + f(x)
}
@ -4388,7 +4388,7 @@ fn main() {
A named function's name can be used wherever you'd use a closure. Another
way of writing the previous example:
```{rust}
```{rust,ignore}
fn twice(x: i32, f: |i32| -> i32) -> i32 {
f(x) + f(x)
}

View file

@ -1559,7 +1559,7 @@ Type parameters can be specified for a trait to make it generic. These appear
after the trait name, using the same syntax used in [generic
functions](#generic-functions).
```
``` ignore
trait Seq<T> {
fn len(&self) -> uint;
fn elt_at(&self, n: uint) -> T;
@ -3217,7 +3217,7 @@ expression's captured environment.
In this example, we define a function `ten_times` that takes a higher-order
function argument, and call it with a lambda expression as an argument.
```
``` ignore
fn ten_times(f: |int|) {
let mut i = 0;
while i < 10 {
@ -3821,7 +3821,7 @@ or `extern`), a sequence of input types and an output type.
An example of a `fn` type:
```
``` ignore
fn add(x: int, y: int) -> int {
return x + y;
}
@ -3849,7 +3849,7 @@ The type of a closure mapping an input of type `A` to an output of type `B` is
An example of creating and calling a closure:
```rust
``` ignore
let captured_var = 10i;
let closure_no_args = || println!("captured_var={}", captured_var);