Book: fixed syntax coloring
This commit is contained in:
parent
382ab92cee
commit
b1605fe8f7
1 changed files with 5 additions and 5 deletions
|
|
@ -322,7 +322,7 @@ to our closure when we pass it to `call_with_one`, so we use `&||`.
|
|||
A quick note about closures that use explicit lifetimes. Sometimes you might have a closure
|
||||
that takes a reference like so:
|
||||
|
||||
```
|
||||
```rust
|
||||
fn call_with_ref<F>(some_closure:F) -> i32
|
||||
where F: Fn(&i32) -> i32 {
|
||||
|
||||
|
|
@ -334,8 +334,8 @@ fn call_with_ref<F>(some_closure:F) -> i32
|
|||
Normally you can specify the lifetime of the parameter to our closure. We
|
||||
could annotate it on the function declaration:
|
||||
|
||||
```ignore
|
||||
fn call_with_ref<'a, F>(some_closure:F) -> i32
|
||||
```rust,ignore
|
||||
fn call_with_ref<'a, F>(some_closure:F) -> i32
|
||||
where F: Fn(&'a 32) -> i32 {
|
||||
```
|
||||
|
||||
|
|
@ -353,11 +353,11 @@ fn call_with_ref<F>(some_closure:F) -> i32
|
|||
where F: for<'a> Fn(&'a 32) -> i32 {
|
||||
```
|
||||
|
||||
This lets the Rust compiler find the minimum lifetime to invoke our closure and
|
||||
This lets the Rust compiler find the minimum lifetime to invoke our closure and
|
||||
satisfy the borrow checker's rules. Our function then compiles and excutes as we
|
||||
expect.
|
||||
|
||||
```
|
||||
```rust
|
||||
fn call_with_ref<F>(some_closure:F) -> i32
|
||||
where F: for<'a> Fn(&'a i32) -> i32 {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue