summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch06-enums-and-pattern-matching
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/doc/book/listings/ch06-enums-and-pattern-matching
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/doc/book/listings/ch06-enums-and-pattern-matching')
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs23
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs10
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs19
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs17
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/src/main.rs18
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs9
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/src/main.rs22
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/src/main.rs12
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/src/main.rs12
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/src/main.rs11
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/src/main.rs19
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/src/main.rs8
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt22
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/src/main.rs8
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/src/main.rs22
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs31
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt18
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/src/main.rs13
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs8
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs24
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs25
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/src/main.rs14
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/src/main.rs14
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/src/main.rs13
68 files changed, 656 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs
new file mode 100644
index 000000000..5b688e0f2
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs
@@ -0,0 +1,23 @@
+fn main() {
+ // ANCHOR: here
+ enum IpAddrKind {
+ V4,
+ V6,
+ }
+
+ struct IpAddr {
+ kind: IpAddrKind,
+ address: String,
+ }
+
+ let home = IpAddr {
+ kind: IpAddrKind::V4,
+ address: String::from("127.0.0.1"),
+ };
+
+ let loopback = IpAddr {
+ kind: IpAddrKind::V6,
+ address: String::from("::1"),
+ };
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs
new file mode 100644
index 000000000..3ba749788
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs
@@ -0,0 +1,10 @@
+// ANCHOR: here
+enum Message {
+ Quit,
+ Move { x: i32, y: i32 },
+ Write(String),
+ ChangeColor(i32, i32, i32),
+}
+// ANCHOR_END: here
+
+fn main() {}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs
new file mode 100644
index 000000000..93dce48cb
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs
@@ -0,0 +1,19 @@
+// ANCHOR: here
+enum Coin {
+ Penny,
+ Nickel,
+ Dime,
+ Quarter,
+}
+
+fn value_in_cents(coin: Coin) -> u8 {
+ match coin {
+ Coin::Penny => 1,
+ Coin::Nickel => 5,
+ Coin::Dime => 10,
+ Coin::Quarter => 25,
+ }
+}
+// ANCHOR_END: here
+
+fn main() {}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs
new file mode 100644
index 000000000..3ba384fba
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs
@@ -0,0 +1,17 @@
+// ANCHOR: here
+#[derive(Debug)] // so we can inspect the state in a minute
+enum UsState {
+ Alabama,
+ Alaska,
+ // --snip--
+}
+
+enum Coin {
+ Penny,
+ Nickel,
+ Dime,
+ Quarter(UsState),
+}
+// ANCHOR_END: here
+
+fn main() {}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/src/main.rs
new file mode 100644
index 000000000..c86190aa7
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-05/src/main.rs
@@ -0,0 +1,18 @@
+fn main() {
+ // ANCHOR: here
+ fn plus_one(x: Option<i32>) -> Option<i32> {
+ match x {
+ // ANCHOR: first_arm
+ None => None,
+ // ANCHOR_END: first_arm
+ // ANCHOR: second_arm
+ Some(i) => Some(i + 1),
+ // ANCHOR_END: second_arm
+ }
+ }
+
+ let five = Some(5);
+ let six = plus_one(five);
+ let none = plus_one(None);
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs
new file mode 100644
index 000000000..dc2bffb91
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs
@@ -0,0 +1,9 @@
+fn main() {
+ // ANCHOR: here
+ let config_max = Some(3u8);
+ match config_max {
+ Some(max) => println!("The maximum is configured to be {}", max),
+ _ => (),
+ }
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/src/main.rs
new file mode 100644
index 000000000..c631e56ba
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-01-defining-enums/src/main.rs
@@ -0,0 +1,22 @@
+// ANCHOR: def
+enum IpAddrKind {
+ V4,
+ V6,
+}
+// ANCHOR_END: def
+
+fn main() {
+ // ANCHOR: instance
+ let four = IpAddrKind::V4;
+ let six = IpAddrKind::V6;
+ // ANCHOR_END: instance
+
+ // ANCHOR: fn_call
+ route(IpAddrKind::V4);
+ route(IpAddrKind::V6);
+ // ANCHOR_END: fn_call
+}
+
+// ANCHOR: fn
+fn route(ip_kind: IpAddrKind) {}
+// ANCHOR_END: fn
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/src/main.rs
new file mode 100644
index 000000000..7d59b811f
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-02-enum-with-data/src/main.rs
@@ -0,0 +1,12 @@
+fn main() {
+ // ANCHOR: here
+ enum IpAddr {
+ V4(String),
+ V6(String),
+ }
+
+ let home = IpAddr::V4(String::from("127.0.0.1"));
+
+ let loopback = IpAddr::V6(String::from("::1"));
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/src/main.rs
new file mode 100644
index 000000000..844a14041
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-03-variants-with-different-data/src/main.rs
@@ -0,0 +1,12 @@
+fn main() {
+ // ANCHOR: here
+ enum IpAddr {
+ V4(u8, u8, u8, u8),
+ V6(String),
+ }
+
+ let home = IpAddr::V4(127, 0, 0, 1);
+
+ let loopback = IpAddr::V6(String::from("::1"));
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/src/main.rs
new file mode 100644
index 000000000..df451be8b
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-04-structs-similar-to-message-enum/src/main.rs
@@ -0,0 +1,11 @@
+// ANCHOR: here
+struct QuitMessage; // unit struct
+struct MoveMessage {
+ x: i32,
+ y: i32,
+}
+struct WriteMessage(String); // tuple struct
+struct ChangeColorMessage(i32, i32, i32); // tuple struct
+ // ANCHOR_END: here
+
+fn main() {}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/src/main.rs
new file mode 100644
index 000000000..66e0b6da1
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-05-methods-on-enums/src/main.rs
@@ -0,0 +1,19 @@
+fn main() {
+ enum Message {
+ Quit,
+ Move { x: i32, y: i32 },
+ Write(String),
+ ChangeColor(i32, i32, i32),
+ }
+
+ // ANCHOR: here
+ impl Message {
+ fn call(&self) {
+ // method body would be defined here
+ }
+ }
+
+ let m = Message::Write(String::from("hello"));
+ m.call();
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/src/main.rs
new file mode 100644
index 000000000..be552bfa5
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-06-option-examples/src/main.rs
@@ -0,0 +1,8 @@
+fn main() {
+ // ANCHOR: here
+ let some_number = Some(5);
+ let some_char = Some('e');
+
+ let absent_number: Option<i32> = None;
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt
new file mode 100644
index 000000000..d4a040e8e
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt
@@ -0,0 +1,22 @@
+$ cargo run
+ Compiling enums v0.1.0 (file:///projects/enums)
+error[E0277]: cannot add `Option<i8>` to `i8`
+ --> src/main.rs:5:17
+ |
+5 | let sum = x + y;
+ | ^ no implementation for `i8 + Option<i8>`
+ |
+ = help: the trait `Add<Option<i8>>` is not implemented for `i8`
+ = help: the following other types implement trait `Add<Rhs>`:
+ <&'a f32 as Add<f32>>
+ <&'a f64 as Add<f64>>
+ <&'a i128 as Add<i128>>
+ <&'a i16 as Add<i16>>
+ <&'a i32 as Add<i32>>
+ <&'a i64 as Add<i64>>
+ <&'a i8 as Add<i8>>
+ <&'a isize as Add<isize>>
+ and 48 others
+
+For more information about this error, try `rustc --explain E0277`.
+error: could not compile `enums` due to previous error
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/src/main.rs
new file mode 100644
index 000000000..ec65565d4
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/src/main.rs
@@ -0,0 +1,8 @@
+fn main() {
+ // ANCHOR: here
+ let x: i8 = 5;
+ let y: Option<i8> = Some(5);
+
+ let sum = x + y;
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/src/main.rs
new file mode 100644
index 000000000..3f909dcaf
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-08-match-arm-multiple-lines/src/main.rs
@@ -0,0 +1,22 @@
+enum Coin {
+ Penny,
+ Nickel,
+ Dime,
+ Quarter,
+}
+
+// ANCHOR: here
+fn value_in_cents(coin: Coin) -> u8 {
+ match coin {
+ Coin::Penny => {
+ println!("Lucky penny!");
+ 1
+ }
+ Coin::Nickel => 5,
+ Coin::Dime => 10,
+ Coin::Quarter => 25,
+ }
+}
+// ANCHOR_END: here
+
+fn main() {}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs
new file mode 100644
index 000000000..a4d500c11
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs
@@ -0,0 +1,31 @@
+#[derive(Debug)]
+enum UsState {
+ Alabama,
+ Alaska,
+ // --snip--
+}
+
+enum Coin {
+ Penny,
+ Nickel,
+ Dime,
+ Quarter(UsState),
+}
+
+// ANCHOR: here
+fn value_in_cents(coin: Coin) -> u8 {
+ match coin {
+ Coin::Penny => 1,
+ Coin::Nickel => 5,
+ Coin::Dime => 10,
+ Coin::Quarter(state) => {
+ println!("State quarter from {:?}!", state);
+ 25
+ }
+ }
+}
+// ANCHOR_END: here
+
+fn main() {
+ value_in_cents(Coin::Quarter(UsState::Alaska));
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt
new file mode 100644
index 000000000..c5a6c51bb
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt
@@ -0,0 +1,18 @@
+$ cargo run
+ Compiling enums v0.1.0 (file:///projects/enums)
+error[E0004]: non-exhaustive patterns: `None` not covered
+ --> src/main.rs:3:15
+ |
+3 | match x {
+ | ^ pattern `None` not covered
+ |
+note: `Option<i32>` defined here
+ = 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!(),
+ |
+
+For more information about this error, try `rustc --explain E0004`.
+error: could not compile `enums` due to previous error
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/src/main.rs
new file mode 100644
index 000000000..f1963d0c9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/src/main.rs
@@ -0,0 +1,13 @@
+fn main() {
+ // ANCHOR: here
+ fn plus_one(x: Option<i32>) -> Option<i32> {
+ match x {
+ Some(i) => Some(i + 1),
+ }
+ }
+ // ANCHOR_END: here
+
+ let five = Some(5);
+ let six = plus_one(five);
+ let none = plus_one(None);
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs
new file mode 100644
index 000000000..735086d4e
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs
@@ -0,0 +1,8 @@
+fn main() {
+ // ANCHOR: here
+ let config_max = Some(3u8);
+ if let Some(max) = config_max {
+ println!("The maximum is configured to be {}", max);
+ }
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs
new file mode 100644
index 000000000..12c4c0fec
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs
@@ -0,0 +1,24 @@
+#[derive(Debug)]
+enum UsState {
+ Alabama,
+ Alaska,
+ // --snip--
+}
+
+enum Coin {
+ Penny,
+ Nickel,
+ Dime,
+ Quarter(UsState),
+}
+
+fn main() {
+ let coin = Coin::Penny;
+ // ANCHOR: here
+ let mut count = 0;
+ match coin {
+ Coin::Quarter(state) => println!("State quarter from {:?}!", state),
+ _ => count += 1,
+ }
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs
new file mode 100644
index 000000000..ba7eda27b
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs
@@ -0,0 +1,25 @@
+#[derive(Debug)]
+enum UsState {
+ Alabama,
+ Alaska,
+ // --snip--
+}
+
+enum Coin {
+ Penny,
+ Nickel,
+ Dime,
+ Quarter(UsState),
+}
+
+fn main() {
+ let coin = Coin::Penny;
+ // ANCHOR: here
+ let mut count = 0;
+ if let Coin::Quarter(state) = coin {
+ println!("State quarter from {:?}!", state);
+ } else {
+ count += 1;
+ }
+ // ANCHOR_END: here
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/src/main.rs
new file mode 100644
index 000000000..6ce0b5998
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-15-binding-catchall/src/main.rs
@@ -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
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/src/main.rs
new file mode 100644
index 000000000..586e23751
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-16-underscore-catchall/src/main.rs
@@ -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
+}
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.lock b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.lock
new file mode 100644
index 000000000..f62e8ac45
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "enums"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.toml b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.toml
new file mode 100644
index 000000000..e959295f9
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "enums"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/src/main.rs b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/src/main.rs
new file mode 100644
index 000000000..e791742ee
--- /dev/null
+++ b/src/doc/book/listings/ch06-enums-and-pattern-matching/no-listing-17-underscore-unit/src/main.rs
@@ -0,0 +1,13 @@
+fn main() {
+ // ANCHOR: here
+ let dice_roll = 9;
+ match dice_roll {
+ 3 => add_fancy_hat(),
+ 7 => remove_fancy_hat(),
+ _ => (),
+ }
+
+ fn add_fancy_hat() {}
+ fn remove_fancy_hat() {}
+ // ANCHOR_END: here
+}