Skip to content

Commit 3c459bb

Browse files
committed
ch18 パターンとマッチングの和訳を最新版に更新
rust-lang/book@19c40bf
1 parent d61d23d commit 3c459bb

File tree

61 files changed

+478
-950
lines changed

Some content is hidden

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

61 files changed

+478
-950
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-01/src/main.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ fn main() {
44
let age: Result<u8, _> = "34".parse();
55

66
if let Some(color) = favorite_color {
7-
println!("Using your favorite color, {}, as the background", color);
7+
// "あなたのお気に入りの色、{color}を背景色に使用します"
8+
println!("Using your favorite color, {color}, as the background");
89
} else if is_tuesday {
10+
// "火曜日は緑の日!"
911
println!("Tuesday is green day!");
1012
} else if let Ok(age) = age {
1113
if age > 30 {
14+
// "紫を背景色に使用します"
1215
println!("Using purple as the background color");
1316
} else {
17+
// "オレンジを背景色に使用します"
1418
println!("Using orange as the background color");
1519
}
1620
} else {
21+
// "青を背景色に使用します"
1722
println!("Using blue as the background color");
1823
}
1924
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-05/output.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ error[E0308]: mismatched types
44
--> src/main.rs:2:9
55
|
66
2 | let (x, y) = (1, 2, 3);
7-
| ^^^^^^ expected a tuple with 3 elements, found one with 2 elements
7+
| ^^^^^^ --------- this expression has type `({integer}, {integer}, {integer})`
8+
| | (この式は型`({integer}, {integer}, {integer})`を持ちます)
9+
| |
10+
| expected a tuple with 3 elements, found one with 2 elements
11+
| (3要素のタプルを予期したのに、2要素のタプルが見つかりました)
812
|
913
= note: expected tuple `({integer}, {integer}, {integer})`
1014
found tuple `(_, _)`
1115

12-
error: aborting due to previous error
13-
1416
For more information about this error, try `rustc --explain E0308`.
15-
error: could not compile `patterns`.
16-
17-
To learn more, run the command again with --verbose.
17+
error: could not compile `patterns` (bin "patterns") due to 1 previous error
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-07/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fn print_coordinates(&(x, y): &(i32, i32)) {
2+
// "現在の位置: ({}, {})"
23
println!("Current location: ({}, {})", x, y);
34
}
45

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
$ cargo run
22
Compiling patterns v0.1.0 (file:///projects/patterns)
3-
error[E0005]: refutable pattern in local binding: `None` not covered
3+
error[E0005]: refutable pattern in local binding
4+
(エラー: ローカル束縛に論駁可能なパターン)
45
--> src/main.rs:3:9
56
|
67
3 | let Some(x) = some_option_value;
78
| ^^^^^^^ pattern `None` not covered
9+
| (パターン`None`がカバーされていません)
810
|
911
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
12+
(注釈: `let`束縛は`struct`や単一の列挙子を持つ`enum`などの「論駁不可能なパターン」を必要とします)
1013
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
11-
help: you might want to use `if let` to ignore the variant that isn't matched
14+
(注釈: さらなる情報についてはhttps://doc.rust-lang.org/book/ch18-02-refutability.htmlを確認してください)
15+
= note: the matched value is of type `Option<i32>`
16+
(注釈: マッチ対象の値は`Option<i32>`型を持ちます)
17+
help: you might want to use `let else` to handle the variant that isn't matched
18+
(ヘルプ: マッチしない列挙子を処理するために`let else`を使用するといいかもしれません)
1219
|
13-
3 | if let Some(x) = some_option_value { /* */ }
14-
|
15-
16-
error: aborting due to previous error
20+
3 | let Some(x) = some_option_value else { todo!() };
21+
| ++++++++++++++++
1722

1823
For more information about this error, try `rustc --explain E0005`.
19-
error: could not compile `patterns`.
20-
21-
To learn more, run the command again with --verbose.
24+
error: could not compile `patterns` (bin "patterns") due to 1 previous error
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
$ cargo run
22
Compiling patterns v0.1.0 (file:///projects/patterns)
3-
warning: irrefutable if-let pattern
4-
--> src/main.rs:2:5
3+
warning: irrefutable `if let` pattern
4+
(警告: 論駁不可能な`if let`パターン)
5+
--> src/main.rs:2:8
56
|
6-
2 | / if let x = 5 {
7-
3 | | println!("{}", x);
8-
4 | | };
9-
| |_____^
7+
2 | if let x = 5 {
8+
| ^^^^^^^^^
109
|
10+
= note: this pattern will always match, so the `if let` is useless
11+
(注釈: このパターンは常にマッチするので`if let`は無意味です)
12+
= help: consider replacing the `if let` with a `let`
13+
(ヘルプ: `if let`を`let`で置き換えることを検討してください)
1114
= note: `#[warn(irrefutable_let_patterns)]` on by default
15+
(注釈: `#[warn(irrefutable_let_patterns)]`はデフォルトでオンです)
1216

17+
warning: `patterns` (bin "patterns") generated 1 warning
1318
Finished dev [unoptimized + debuginfo] target(s) in 0.39s
1419
Running `target/debug/patterns`
1520
5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-11/src/main.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ fn main() {
44
let y = 10;
55

66
match x {
7+
// 50だったよ
78
Some(50) => println!("Got 50"),
8-
Some(y) => println!("Matched, y = {:?}", y),
9+
// マッチしたよ、y = {y}
10+
Some(y) => println!("Matched, y = {y}"),
11+
// 既定のケース、x = {:?}
912
_ => println!("Default case, x = {:?}", x),
1013
}
1114

12-
println!("at the end: x = {:?}, y = {:?}", x, y);
15+
// 最後には: x = {:?}, y = {y}
16+
println!("at the end: x = {:?}, y = {y}", x);
1317
// ANCHOR_END: here
1418
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-14/src/main.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ fn main() {
88
let p = Point { x: 0, y: 7 };
99

1010
match p {
11-
Point { x, y: 0 } => println!("On the x axis at {}", x),
12-
Point { x: 0, y } => println!("On the y axis at {}", y),
13-
Point { x, y } => println!("On neither axis: ({}, {})", x, y),
11+
// x軸上の{x}
12+
Point { x, y: 0 } => println!("On the x axis at {x}"),
13+
// y軸上の{y}
14+
Point { x: 0, y } => println!("On the y axis at {y}"),
15+
// どちらの軸上でもない: ({x}, {y})
16+
Point { x, y } => {
17+
println!("On neither axis: ({x}, {y})");
18+
}
1419
}
1520
}
1621
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-15/src/main.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ fn main() {
1010

1111
match msg {
1212
Message::Quit => {
13-
println!("The Quit variant has no data to destructure.")
13+
// Quit列挙子には分配すべきデータがない
14+
println!("The Quit variant has no data to destructure.");
1415
}
1516
Message::Move { x, y } => {
16-
println!(
17-
"Move in the x direction {} and in the y direction {}",
18-
x, y
19-
);
17+
// x方向に{x}、y方向に{y}だけ動く
18+
println!("Move in the x direction {x} and in the y direction {y}");
19+
}
20+
Message::Write(text) => {
21+
// テキストメッセージ: {text}
22+
println!("Text message: {text}");
23+
}
24+
Message::ChangeColor(r, g, b) => {
25+
// 色を赤{r}, 緑{g}, 青{b}に変更
26+
println!("Change the color to red {r}, green {g}, and blue {b}",)
2027
}
21-
Message::Write(text) => println!("Text message: {}", text),
22-
Message::ChangeColor(r, g, b) => println!(
23-
"Change the color to red {}, green {}, and blue {}",
24-
r, g, b
25-
),
2628
}
2729
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-16/src/main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ fn main() {
1414
let msg = Message::ChangeColor(Color::Hsv(0, 160, 255));
1515

1616
match msg {
17-
Message::ChangeColor(Color::Rgb(r, g, b)) => println!(
18-
"Change the color to red {}, green {}, and blue {}",
19-
r, g, b
20-
),
21-
Message::ChangeColor(Color::Hsv(h, s, v)) => println!(
22-
"Change the color to hue {}, saturation {}, and value {}",
23-
h, s, v
24-
),
17+
Message::ChangeColor(Color::Rgb(r, g, b)) => {
18+
// 色を赤{r}, 緑{g}, 青{b}に変更
19+
println!("Change color to red {r}, green {g}, and blue {b}");
20+
}
21+
Message::ChangeColor(Color::Hsv(h, s, v)) => {
22+
// 色を色相{h}, 彩度{s}, 明度{v}に変更
23+
println!("Change color to hue {h}, saturation {s}, value {v}")
24+
}
2525
_ => (),
2626
}
2727
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-17/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fn foo(_: i32, y: i32) {
2+
// このコードは、y引数を使うだけです: {}
23
println!("This code only uses the y parameter: {}", y);
34
}
45

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch18-patterns-and-matching/listing-18-18/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ fn main() {
55

66
match (setting_value, new_setting_value) {
77
(Some(_), Some(_)) => {
8+
// 既存の値の変更を上書きできません
89
println!("Can't overwrite an existing customized value");
910
}
1011
_ => {
1112
setting_value = new_setting_value;
1213
}
1314
}
1415

16+
// 設定は{:?}です
1517
println!("setting is {:?}", setting_value);
1618
// ANCHOR_END: here
1719
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "patterns"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

0 commit comments

Comments
 (0)