Skip to content

Commit 1139c13

Browse files
committed
ch08 一般的なコレクションの和訳を最新版に更新
rust-lang/book@19c40bf
1 parent 9eb0aa4 commit 1139c13

File tree

55 files changed

+685
-812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+685
-812
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "collections"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "collections"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "collections"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "collections"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
fn main() {
22
// ANCHOR: here
3-
{
4-
let v = vec![1, 2, 3, 4];
3+
let v = vec![1, 2, 3, 4, 5];
54

6-
// vで作業をする
7-
} // <- vはここでスコープを抜け、解放される
8-
// ANCHOR_END: here
5+
let third: &i32 = &v[2];
6+
// "3つ目の要素は{third}です"
7+
println!("The third element is {third}");
8+
9+
let third: Option<&i32> = v.get(2);
10+
match third {
11+
// "3つ目の要素は{third}です"
12+
Some(third) => println!("The third element is {third}"),
13+
// "3つ目の要素はありません。"
14+
None => println!("There is no third element."),
15+
}
16+
// ANCHOR_END: here
917
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "collections"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

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

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

5-
let third: &i32 = &v[2];
6-
println!("The third element is {}", third);
7-
8-
match v.get(2) {
9-
// "3つ目の要素は{}です"
10-
Some(third) => println!("The third element is {}", third),
11-
// "3つ目の要素はありません。"
12-
None => println!("There is no third element."),
13-
}
5+
let does_not_exist = &v[100];
6+
let does_not_exist = v.get(100);
147
// ANCHOR_END: here
158
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "collections"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immuta
77
4 | let first = &v[0];
88
| - immutable borrow occurs here
99
| (不変借用はここで発生しています)
10-
5 |
10+
5 |
1111
6 | v.push(6);
1212
| ^^^^^^^^^ mutable borrow occurs here
1313
| (可変借用はここで発生しています)
14-
7 |
15-
8 | println!("The first element is: {}", first);
16-
| ----- immutable borrow later used here
17-
| (その後、不変借用はここで使われています)
18-
19-
error: aborting due to previous error
14+
7 |
15+
8 | println!("The first element is: {first}");
16+
| ------- immutable borrow later used here
17+
| (その後、不変借用はここで使われています)
2018

2119
For more information about this error, try `rustc --explain E0502`.
22-
error: could not compile `collections`.
23-
24-
To learn more, run the command again with --verbose.
20+
error: could not compile `collections` (bin "collections") due to 1 previous error
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
fn main() {
22
// ANCHOR: here
3-
let v = vec![1, 2, 3, 4, 5];
3+
let mut v = vec![1, 2, 3, 4, 5];
44

5-
let does_not_exist = &v[100];
6-
let does_not_exist = v.get(100);
5+
let first = &v[0];
6+
7+
v.push(6);
8+
9+
// "最初の要素は: {first}"
10+
println!("The first element is: {first}");
711
// ANCHOR_END: here
812
}

0 commit comments

Comments
 (0)