Skip to content

Commit d2d9bbb

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

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
}
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: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
fn main() {
22
// ANCHOR: here
3-
let mut v = vec![1, 2, 3, 4, 5];
4-
5-
let first = &v[0];
6-
7-
v.push(6);
8-
9-
println!("The first element is: {}", first);
3+
let v = vec![100, 32, 57];
4+
for i in &v {
5+
println!("{i}");
6+
}
107
// ANCHOR_END: here
118
}
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn main() {
22
// ANCHOR: here
3-
let v = vec![100, 32, 57];
4-
for i in &v {
5-
println!("{}", i);
3+
let mut v = vec![100, 32, 57];
4+
for i in &mut v {
5+
*i += 50;
66
}
77
// ANCHOR_END: here
88
}
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: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
fn main() {
22
// ANCHOR: here
3-
let mut v = vec![100, 32, 57];
4-
for i in &mut v {
5-
*i += 50;
3+
enum SpreadsheetCell {
4+
Int(i32),
5+
Float(f64),
6+
Text(String),
67
}
8+
9+
let row = vec![
10+
SpreadsheetCell::Int(3),
11+
SpreadsheetCell::Text(String::from("blue")),
12+
SpreadsheetCell::Float(10.12),
13+
];
714
// ANCHOR_END: here
815
}
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: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
fn main() {
22
// ANCHOR: here
3-
enum SpreadsheetCell {
4-
Int(i32),
5-
Float(f64),
6-
Text(String),
7-
}
3+
{
4+
let v = vec![1, 2, 3, 4];
85

9-
let row = vec![
10-
SpreadsheetCell::Int(3),
11-
SpreadsheetCell::Text(String::from("blue")),
12-
SpreadsheetCell::Float(10.12),
13-
];
14-
// ANCHOR_END: here
6+
// vで作業をする
7+
} // <- vはここでスコープを抜け、解放される
8+
// ANCHOR_END: here
159
}
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: 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]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ fn main() {
33
let mut s1 = String::from("foo");
44
let s2 = "bar";
55
s1.push_str(s2);
6-
println!("s2 is {}", s2);
6+
println!("s2 is {s2}");
77
// ANCHOR_END: here
88
}
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]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ fn main() {
22
// ANCHOR: here
33
let s1 = String::from("Hello, ");
44
let s2 = String::from("world!");
5-
let s3 = s1 + &s2; // note s1 has been moved here and can no longer be used
5+
let s3 = s1 + &s2; // s1はムーブされ、もう使用できないことに注意
66
// ANCHOR_END: here
77
}
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: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
$ cargo run
22
Compiling collections v0.1.0 (file:///projects/collections)
3-
error[E0277]: the type `std::string::String` cannot be indexed by `{integer}`
4-
--> src/main.rs:3:13
3+
error[E0277]: the type `String` cannot be indexed by `{integer}`
4+
(エラー: 型`String`は`{Integer}`で添え字アクセスできませんん)
5+
--> src/main.rs:3:16
56
|
67
3 | let h = s1[0];
7-
| ^^^^^ `std::string::String` cannot be indexed by `{integer}`
8+
| ^ `String` cannot be indexed by `{integer}`
9+
| (`String`は`{Integer}`で添え字アクセスできません)
810
|
9-
= help: the trait `std::ops::Index<{integer}>` is not implemented for `std::string::String`
10-
11-
error: aborting due to previous error
11+
= help: the trait `Index<{integer}>` is not implemented for `String`
12+
(ヘルプ: `Index<{Integer}>`というトレイトが`String`に対して実装されていません)
13+
= help: the following other types implement trait `Index<Idx>`:
14+
(ヘルプ: 以下の型であればトレイト`Index<Idx>`を実装しています:)
15+
<String as Index<RangeFull>>
16+
<String as Index<std::ops::Range<usize>>>
17+
<String as Index<RangeFrom<usize>>>
18+
<String as Index<RangeTo<usize>>>
19+
<String as Index<RangeInclusive<usize>>>
20+
<String as Index<RangeToInclusive<usize>>>
1221

1322
For more information about this error, try `rustc --explain E0277`.
14-
error: could not compile `collections`.
15-
16-
To learn more, run the command again with --verbose.
23+
error: could not compile `collections` (bin "collections") due to 1 previous error
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]

0 commit comments

Comments
 (0)