Skip to content

Commit 0d83174

Browse files
authored
Merge pull request #94 from woodyZootopia/translate_08-01
Update 08-01
2 parents ca2c08e + cb283ab commit 0d83174

File tree

4 files changed

+100
-145
lines changed

4 files changed

+100
-145
lines changed

listings/ch08-common-collections/listing-08-04/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fn main() {
33
{
44
let v = vec![1, 2, 3, 4];
55

6-
// do stuff with v
7-
} // <- v goes out of scope and is freed here
6+
// vで作業をする
7+
} // <- vはここでスコープを抜け、解放される
88
// ANCHOR_END: here
99
}

listings/ch08-common-collections/listing-08-05/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ fn main() {
66
println!("The third element is {}", third);
77

88
match v.get(2) {
9+
// "3つ目の要素は{}です"
910
Some(third) => println!("The third element is {}", third),
11+
// "3つ目の要素はありません。"
1012
None => println!("There is no third element."),
1113
}
1214
// ANCHOR_END: here

listings/ch08-common-collections/listing-08-07/output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
$ cargo run
22
Compiling collections v0.1.0 (file:///projects/collections)
33
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
4+
(エラー: 不変としても借用されているので、`v`を可変で借用できません)
45
--> src/main.rs:6:5
56
|
67
4 | let first = &v[0];
78
| - immutable borrow occurs here
9+
| (不変借用はここで発生しています)
810
5 |
911
6 | v.push(6);
1012
| ^^^^^^^^^ mutable borrow occurs here
13+
| (可変借用はここで発生しています)
1114
7 |
1215
8 | println!("The first element is: {}", first);
1316
| ----- immutable borrow later used here
17+
| (その後、不変借用はここで使われています)
1418

1519
error: aborting due to previous error
1620

0 commit comments

Comments
 (0)