-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
526 additions
and
610 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
4 changes: 2 additions & 2 deletions
4
listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
6 changes: 3 additions & 3 deletions
6
listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
...ngs/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
.../ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
6 changes: 3 additions & 3 deletions
6
...ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// ANCHOR: here | ||
struct QuitMessage; // unit struct | ||
struct QuitMessage; // ユニット構造体 | ||
struct MoveMessage { | ||
x: i32, | ||
y: i32, | ||
} | ||
struct WriteMessage(String); // tuple struct | ||
struct ChangeColorMessage(i32, i32, i32); // tuple struct | ||
struct WriteMessage(String); // タプル構造体 | ||
struct ChangeColorMessage(i32, i32, i32); // タプル構造体 | ||
// ANCHOR_END: here | ||
|
||
fn main() {} |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
2 changes: 1 addition & 1 deletion
2
listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
21 changes: 13 additions & 8 deletions
21
listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
$ cargo run | ||
Compiling enums v0.1.0 (file:///projects/enums) | ||
error[E0277]: cannot add `std::option::Option<i8>` to `i8` | ||
error[E0277]: cannot add `Option<i8>` to `i8` | ||
(エラー: `Option<i8>`を`i8`に足すことはできません) | ||
--> src/main.rs:5:17 | ||
| | ||
5 | let sum = x + y; | ||
| ^ no implementation for `i8 + std::option::Option<i8>` | ||
| ^ no implementation for `i8 + Option<i8>` | ||
(`i8 + `Option<i8>`のための実装がありません) | ||
| | ||
= help: the trait `std::ops::Add<std::option::Option<i8>>` is not implemented for `i8` | ||
|
||
error: aborting due to previous error | ||
= help: the trait `Add<Option<i8>>` is not implemented for `i8` | ||
(ヘルプ: トレイト`Add<Option<i8>`が`i8`に対して実装されていません) | ||
= help: the following other types implement trait `Add<Rhs>`: | ||
(ヘルプ: 以下の型であればトレイト`Add<Rhs>`を実装しています:) | ||
<i8 as Add> | ||
<i8 as Add<&i8>> | ||
<&'a i8 as Add<i8>> | ||
<&i8 as Add<&i8>> | ||
|
||
For more information about this error, try `rustc --explain E0277`. | ||
error: could not compile `enums`. | ||
|
||
To learn more, run the command again with --verbose. | ||
error: could not compile `enums` (bin "enums") due to 1 previous error |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
21 changes: 15 additions & 6 deletions
21
listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
$ cargo run | ||
Compiling enums v0.1.0 (file:///projects/enums) | ||
error[E0004]: non-exhaustive patterns: `None` not covered | ||
(エラー: 包括的でないパターン: `None`が網羅されていません) | ||
--> src/main.rs:3:15 | ||
| | ||
3 | match x { | ||
| ^ pattern `None` not covered | ||
(パターン`None`が網羅されていません) | ||
| | ||
note: `Option<i32>` defined here | ||
--> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:570:1 | ||
::: /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:574:5 | ||
| | ||
= note: not covered | ||
= note: the matched value is of type `Option<i32>` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | ||
(ヘルプ: ワイルドカードパターンか、以下に示すように明示的なパターンを持つアームを追加することで、すべての可能な場合が確実に処理されるようにしてください) | ||
| | ||
4 ~ Some(i) => Some(i + 1), | ||
5 ~ None => todo!(), | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0004`. | ||
error: could not compile `enums`. | ||
|
||
To learn more, run the command again with --verbose. | ||
error: could not compile `enums` (bin "enums") due to 1 previous error |
12 changes: 0 additions & 12 deletions
12
listings/ch06-enums-and-pattern-matching/no-listing-11-underscore-placeholder/src/main.rs
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
6 changes: 3 additions & 3 deletions
6
listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
fn main() { | ||
let some_u8_value = Some(0u8); | ||
// ANCHOR: here | ||
if let Some(3) = some_u8_value { | ||
println!("three"); | ||
let config_max = Some(3u8); | ||
if let Some(max) = config_max { | ||
println!("The maximum is configured to be {}", max); | ||
} | ||
// ANCHOR_END: here | ||
} |
3 changes: 1 addition & 2 deletions
3
listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
enum UsState { | ||
Alabama, | ||
Alaska, | ||
// --snip-- | ||
// --略-- | ||
} | ||
|
||
enum Coin { | ||
|
3 changes: 1 addition & 2 deletions
3
...s/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
enum UsState { | ||
Alabama, | ||
Alaska, | ||
// --snip-- | ||
// --略-- | ||
} | ||
|
||
enum Coin { | ||
|
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
...ting-11-underscore-placeholder/Cargo.toml → ...no-listing-15-binding-catchall/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
authors = ["Your Name <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[dependencies] |
14 changes: 14 additions & 0 deletions
14
listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fn main() { | ||
// ANCHOR: here | ||
let dice_roll = 9; | ||
match dice_roll { | ||
3 => add_fancy_hat(), | ||
7 => remove_fancy_hat(), | ||
other => move_player(other), | ||
} | ||
|
||
fn add_fancy_hat() {} | ||
fn remove_fancy_hat() {} | ||
fn move_player(num_spaces: u8) {} | ||
// ANCHOR_END: here | ||
} |
6 changes: 6 additions & 0 deletions
6
listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
14 changes: 14 additions & 0 deletions
14
listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fn main() { | ||
// ANCHOR: here | ||
let dice_roll = 9; | ||
match dice_roll { | ||
3 => add_fancy_hat(), | ||
7 => remove_fancy_hat(), | ||
_ => reroll(), | ||
} | ||
|
||
fn add_fancy_hat() {} | ||
fn remove_fancy_hat() {} | ||
fn reroll() {} | ||
// ANCHOR_END: here | ||
} |
6 changes: 6 additions & 0 deletions
6
listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "enums" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
Oops, something went wrong.