Skip to content

Commit 0de9bcf

Browse files
committed
ch06 Enumとパターンマッチングの和訳を最新版に更新
rust-lang/book@19c40bf
1 parent 7dce9e1 commit 0de9bcf

File tree

44 files changed

+526
-610
lines changed

Some content is hidden

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

44 files changed

+526
-610
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "enums"
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 = "enums"
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 = "enums"
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 = "enums"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ANCHOR: here
2-
#[derive(Debug)] // so we can inspect the state in a minute
2+
#[derive(Debug)] // すぐに州を検査できるように
33
enum UsState {
44
Alabama,
55
Alaska,
6-
// --snip--
6+
// ----
77
}
88

99
enum Coin {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "enums"
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 = "enums"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn main() {
22
// ANCHOR: here
3-
let some_u8_value = Some(0u8);
4-
match some_u8_value {
5-
Some(3) => println!("three"),
3+
let config_max = Some(3u8);
4+
match config_max {
5+
Some(max) => println!("The maximum is configured to be {}", max),
66
_ => (),
77
}
88
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "enums"
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 = "enums"
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 = "enums"
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 = "enums"
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,11 +1,11 @@
11
// ANCHOR: here
2-
struct QuitMessage; // unit struct
2+
struct QuitMessage; // ユニット構造体
33
struct MoveMessage {
44
x: i32,
55
y: i32,
66
}
7-
struct WriteMessage(String); // tuple struct
8-
struct ChangeColorMessage(i32, i32, i32); // tuple struct
7+
struct WriteMessage(String); // タプル構造体
8+
struct ChangeColorMessage(i32, i32, i32); // タプル構造体
99
// ANCHOR_END: here
1010

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

76
[dependencies]

listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
// ANCHOR: here
1010
impl Message {
1111
fn call(&self) {
12-
// method body would be defined here
12+
// メソッド本体はここで定義されます
1313
}
1414
}
1515

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

76
[dependencies]

listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() {
22
// ANCHOR: here
33
let some_number = Some(5);
4-
let some_string = Some("a string");
4+
let some_char = Some('e');
55

66
let absent_number: Option<i32> = None;
77
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "enums"
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,16 +1,21 @@
11
$ cargo run
22
Compiling enums v0.1.0 (file:///projects/enums)
3-
error[E0277]: cannot add `std::option::Option<i8>` to `i8`
3+
error[E0277]: cannot add `Option<i8>` to `i8`
4+
(エラー: `Option<i8>`を`i8`に足すことはできません)
45
--> src/main.rs:5:17
56
|
67
5 | let sum = x + y;
7-
| ^ no implementation for `i8 + std::option::Option<i8>`
8+
| ^ no implementation for `i8 + Option<i8>`
9+
(`i8 + `Option<i8>`のための実装がありません)
810
|
9-
= help: the trait `std::ops::Add<std::option::Option<i8>>` is not implemented for `i8`
10-
11-
error: aborting due to previous error
11+
= help: the trait `Add<Option<i8>>` is not implemented for `i8`
12+
(ヘルプ: トレイト`Add<Option<i8>`が`i8`に対して実装されていません)
13+
= help: the following other types implement trait `Add<Rhs>`:
14+
(ヘルプ: 以下の型であればトレイト`Add<Rhs>`を実装しています:)
15+
<i8 as Add>
16+
<i8 as Add<&i8>>
17+
<&'a i8 as Add<i8>>
18+
<&i8 as Add<&i8>>
1219

1320
For more information about this error, try `rustc --explain E0277`.
14-
error: could not compile `enums`.
15-
16-
To learn more, run the command again with --verbose.
21+
error: could not compile `enums` (bin "enums") due to 1 previous error
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "enums"
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 = "enums"
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 = "enums"
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,16 +1,25 @@
11
$ cargo run
22
Compiling enums v0.1.0 (file:///projects/enums)
33
error[E0004]: non-exhaustive patterns: `None` not covered
4+
(エラー: 包括的でないパターン: `None`が網羅されていません)
45
--> src/main.rs:3:15
56
|
67
3 | match x {
78
| ^ pattern `None` not covered
9+
(パターン`None`が網羅されていません)
10+
|
11+
note: `Option<i32>` defined here
12+
--> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:570:1
13+
::: /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:574:5
14+
|
15+
= note: not covered
16+
= note: the matched value is of type `Option<i32>`
17+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
18+
(ヘルプ: ワイルドカードパターンか、以下に示すように明示的なパターンを持つアームを追加することで、すべての可能な場合が確実に処理されるようにしてください)
19+
|
20+
4 ~ Some(i) => Some(i + 1),
21+
5 ~ None => todo!(),
822
|
9-
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
10-
11-
error: aborting due to previous error
1223

1324
For more information about this error, try `rustc --explain E0004`.
14-
error: could not compile `enums`.
15-
16-
To learn more, run the command again with --verbose.
25+
error: could not compile `enums` (bin "enums") due to 1 previous error

listings/ch06-enums-and-pattern-matching/no-listing-11-underscore-placeholder/src/main.rs

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "enums"
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,8 +1,8 @@
11
fn main() {
2-
let some_u8_value = Some(0u8);
32
// ANCHOR: here
4-
if let Some(3) = some_u8_value {
5-
println!("three");
3+
let config_max = Some(3u8);
4+
if let Some(max) = config_max {
5+
println!("The maximum is configured to be {}", max);
66
}
77
// ANCHOR_END: here
88
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "enums"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
enum UsState {
33
Alabama,
44
Alaska,
5-
// --snip--
5+
// ----
66
}
77

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

76
[dependencies]

listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
enum UsState {
33
Alabama,
44
Alaska,
5-
// --snip--
5+
// ----
66
}
77

88
enum Coin {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "enums"
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
@@ -0,0 +1,14 @@
1+
fn main() {
2+
// ANCHOR: here
3+
let dice_roll = 9;
4+
match dice_roll {
5+
3 => add_fancy_hat(),
6+
7 => remove_fancy_hat(),
7+
other => move_player(other),
8+
}
9+
10+
fn add_fancy_hat() {}
11+
fn remove_fancy_hat() {}
12+
fn move_player(num_spaces: u8) {}
13+
// ANCHOR_END: here
14+
}

listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.lock

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "enums"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn main() {
2+
// ANCHOR: here
3+
let dice_roll = 9;
4+
match dice_roll {
5+
3 => add_fancy_hat(),
6+
7 => remove_fancy_hat(),
7+
_ => reroll(),
8+
}
9+
10+
fn add_fancy_hat() {}
11+
fn remove_fancy_hat() {}
12+
fn reroll() {}
13+
// ANCHOR_END: here
14+
}

listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.lock

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "enums"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

0 commit comments

Comments
 (0)