Skip to content

Commit 10abb66

Browse files
committed
Update references-and-borrowing.md
add as 2nd example.
1 parent a3f5d8a commit 10abb66

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/doc/book/references-and-borrowing.md

+18
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ let (v1, v2, answer) = foo(v1, v2);
6161
This is not idiomatic Rust, however, as it doesn’t take advantage of borrowing. Here’s
6262
the first step:
6363

64+
```rust
65+
fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> i32 {
66+
// do stuff with v1 and v2
67+
68+
// return the answer
69+
42
70+
}
71+
72+
let v1 = vec![1, 2, 3];
73+
let v2 = vec![1, 2, 3];
74+
75+
let answer = foo(&v1, &v2);
76+
77+
// we can use v1 and v2 here!
78+
```
79+
80+
A more concrete example:
81+
6482
```rust
6583
fn main() {
6684
// Don't worry if you don't understand how `fold` works, the point here is that an immutable reference is borrowed.

0 commit comments

Comments
 (0)