From 7cd0748d8d3771e2f1701d5130cd45642fd516ef Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:09:46 +0200 Subject: [PATCH 01/30] Converted Listing 7-1 into `` --- src/ch07-02-defining-modules-to-control-scope-and-privacy.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index 4a25c161be..02fb887591 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -114,14 +114,13 @@ restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to define some modules and function signatures; this code is the front of house section. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-01/src/lib.rs}} ``` -Listing 7-1: A `front_of_house` module containing other -modules that then contain functions + We define a module with the `mod` keyword followed by the name of the module (in this case, `front_of_house`). The body of the module then goes inside curly From 3d32026903940dda2096109f885cb446bcc2e390 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:11:50 +0200 Subject: [PATCH 02/30] Converted Listing 7-2 into `` --- src/ch07-02-defining-modules-to-control-scope-and-privacy.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index 02fb887591..0a711f9e6e 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -142,6 +142,8 @@ known as the *module tree*. Listing 7-2 shows the module tree for the structure in Listing 7-1. ++ ```text crate └── front_of_house @@ -154,8 +156,7 @@ crate └── take_payment ``` -Listing 7-2: The module tree for the code in Listing -7-1 + This tree shows how some of the modules nest inside other modules; for example, `hosting` nests inside `front_of_house`. The tree also shows that some modules From 12c4a764834d0169e8492e5ddd959acd03242985 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:15:03 +0200 Subject: [PATCH 03/30] Converted Listing 7-3 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 4201ea3db2..39bd541ce1 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -29,14 +29,13 @@ The `eat_at_restaurant` function is part of our library crate’s public API, so we mark it with the `pub` keyword. In the [“Exposing Paths with the `pub` Keyword”][pub] section, we’ll go into more detail about `pub`. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-03/src/lib.rs}} ``` -Listing 7-3: Calling the `add_to_waitlist` function using -absolute and relative paths + The first time we call the `add_to_waitlist` function in `eat_at_restaurant`, we use an absolute path. The `add_to_waitlist` function is defined in the same From 4513d38611fa24420ec853ceea98b94bcfaf5236 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:17:18 +0200 Subject: [PATCH 04/30] Converted Listing 7-4 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 39bd541ce1..bdb9911db5 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -69,12 +69,13 @@ each other. Let’s try to compile Listing 7-3 and find out why it won’t compile yet! The errors we get are shown in Listing 7-4. ++ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-03/output.txt}} ``` -Listing 7-4: Compiler errors from building the code in -Listing 7-3 + The error messages say that module `hosting` is private. In other words, we have the correct paths for the `hosting` module and the `add_to_waitlist` From f79de2535d494dbb068c05e8f9b5465ddcccee3f Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:23:06 +0200 Subject: [PATCH 05/30] Converted Listing 7-5 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index bdb9911db5..7e3faeda8e 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -105,14 +105,13 @@ private. We want the `eat_at_restaurant` function in the parent module to have access to the `add_to_waitlist` function in the child module, so we mark the `hosting` module with the `pub` keyword, as shown in Listing 7-5. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-05/src/lib.rs}} ``` -Listing 7-5: Declaring the `hosting` module as `pub` to -use it from `eat_at_restaurant` + Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. From 1cd2240da1142f6bb25d9e32743303ecf0c60d02 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:28:46 +0200 Subject: [PATCH 06/30] Converted Listing 7-6 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 7e3faeda8e..9b92dfae31 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -116,12 +116,13 @@ access to the `add_to_waitlist` function in the child module, so we mark the Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. ++ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-05/output.txt}} ``` -Listing 7-6: Compiler errors from building the code in -Listing 7-5 + What happened? Adding the `pub` keyword in front of `mod hosting` makes the module public. With this change, if we can access `front_of_house`, we can From e29723539925a93563347c93cf2093142905849e Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:31:47 +0200 Subject: [PATCH 07/30] Converted Listing 7-7 to `` --- ...-03-paths-for-referring-to-an-item-in-the-module-tree.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 9b92dfae31..1e791d22d6 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -140,15 +140,13 @@ modules. Let’s also make the `add_to_waitlist` function public by adding the `pub` keyword before its definition, as in Listing 7-7. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs}} ``` -Listing 7-7: Adding the `pub` keyword to `mod hosting` -and `fn add_to_waitlist` lets us call the function from -`eat_at_restaurant` + Now the code will compile! To see why adding the `pub` keyword lets us use these paths in `eat_at_restaurant` with respect to the privacy rules, let’s look From 8f5e623c99395312b766148f9e74e2691d1c09fd Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:33:53 +0200 Subject: [PATCH 08/30] Converted Listing 7-8 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 1e791d22d6..47fd9a0d11 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -214,14 +214,13 @@ function `fix_incorrect_order` defined in the `back_of_house` module calls the function `deliver_order` defined in the parent module by specifying the path to `deliver_order`, starting with `super`. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-08/src/lib.rs}} ``` -Listing 7-8: Calling a function using a relative path -starting with `super` + The `fix_incorrect_order` function is in the `back_of_house` module, so we can use `super` to go to the parent module of `back_of_house`, which in this case From 2a52d9c7a7442d1881ce7b32fed3479e0a7da2c0 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:36:11 +0200 Subject: [PATCH 09/30] Convert Listing 7-9 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 47fd9a0d11..723372386c 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -244,14 +244,13 @@ comes with a meal, but the chef decides which fruit accompanies the meal based on what’s in season and in stock. The available fruit changes quickly, so customers can’t choose the fruit or even see which fruit they’ll get. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs}} ``` -Listing 7-9: A struct with some public fields and some -private fields + Because the `toast` field in the `back_of_house::Breakfast` struct is public, in `eat_at_restaurant` we can write and read to the `toast` field using dot From cc71c024eee1a7f0a93f723c88f9fda4d9e43f03 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:39:17 +0200 Subject: [PATCH 10/30] Converted Listing 7-10 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 723372386c..da07d9fd83 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -268,14 +268,13 @@ have such a function, we couldn’t create an instance of `Breakfast` in In contrast, if we make an enum public, all of its variants are then public. We only need the `pub` before the `enum` keyword, as shown in Listing 7-10. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-10/src/lib.rs}} ``` -Listing 7-10: Designating an enum as public makes all its -variants public + Because we made the `Appetizer` enum public, we can use the `Soup` and `Salad` variants in `eat_at_restaurant`. From db0262caaa29e23fed71acad17beaf6f0f788aab Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:41:25 +0200 Subject: [PATCH 11/30] Converted Listing 7-11 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index defa950c6b..0a77bb480d 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -12,14 +12,13 @@ scope of the `eat_at_restaurant` function so we only have to specify `hosting::add_to_waitlist` to call the `add_to_waitlist` function in `eat_at_restaurant`. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-11/src/lib.rs}} ``` -Listing 7-11: Bringing a module into scope with -`use` + Adding `use` and a path in a scope is similar to creating a symbolic link in the filesystem. By adding `use crate::front_of_house::hosting` in the crate From c1ba6757732182f93e4a454430dcb5a813003200 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:03:53 +0200 Subject: [PATCH 12/30] Converted Listing 7-12 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 0a77bb480d..77940dcf77 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -31,14 +31,13 @@ Note that `use` only creates the shortcut for the particular scope in which the child module named `customer`, which is then a different scope than the `use` statement, so the function body won’t compile. -Filename: src/lib.rs + ```rust,noplayground,test_harness,does_not_compile,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-12/src/lib.rs}} ``` -Listing 7-12: A `use` statement only applies in the scope -it’s in + The compiler error shows that the shortcut no longer applies within the `customer` module: From 6178940e1881023f82099dde9e83b968c1b12d1c Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:10:09 +0200 Subject: [PATCH 13/30] Convert Listing 7-13 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 77940dcf77..8951835035 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -58,14 +58,13 @@ crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in `eat_at_restaurant`, rather than specifying the `use` path all the way out to the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-13/src/lib.rs}} ``` -Listing 7-13: Bringing the `add_to_waitlist` function -into scope with `use`, which is unidiomatic + Although both Listing 7-11 and Listing 7-13 accomplish the same task, Listing 7-11 is the idiomatic way to bring a function into scope with `use`. Bringing From 9996cae5f591244c65f726a5aa15e73dc991cbc1 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:12:34 +0200 Subject: [PATCH 14/30] Convert Listing 7-14 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 8951835035..5b1b05cf91 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -79,14 +79,13 @@ it’s idiomatic to specify the full path. Listing 7-14 shows the idiomatic way to bring the standard library’s `HashMap` struct into the scope of a binary crate. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-14/src/main.rs}} ``` -Listing 7-14: Bringing `HashMap` into scope in an -idiomatic way + There’s no strong reason behind this idiom: it’s just the convention that has emerged, and folks have gotten used to reading and writing Rust code this way. From 4f860403624a14a912b6846a8baa2515c3107397 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:16:20 +0200 Subject: [PATCH 15/30] Convert Listing 7-15 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 5b1b05cf91..a32ee60f90 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -95,14 +95,13 @@ into scope with `use` statements, because Rust doesn’t allow that. Listing 7-1 shows how to bring two `Result` types into scope that have the same name but different parent modules, and how to refer to them. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-15/src/lib.rs:here}} ``` -Listing 7-15: Bringing two types with the same name into -the same scope requires using their parent modules. + As you can see, using the parent modules distinguishes the two `Result` types. If instead we specified `use std::fmt::Result` and `use std::io::Result`, we’d From 744d4df1bf8323faebe3743076ae3dad53a8ec9a Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:27:23 +0200 Subject: [PATCH 16/30] Convert Listing 7-16 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index a32ee60f90..01a8019d47 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -115,14 +115,13 @@ into the same scope with `use`: after the path, we can specify `as` and a new local name, or *alias*, for the type. Listing 7-16 shows another way to write the code in Listing 7-15 by renaming one of the two `Result` types using `as`. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-16/src/lib.rs:here}} ``` -Listing 7-16: Renaming a type when it’s brought into -scope with the `as` keyword + In the second `use` statement, we chose the new name `IoResult` for the `std::io::Result` type, which won’t conflict with the `Result` from `std::fmt` From cd5a840e50e243e70b9d7033cbeb0514986945c7 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:29:24 +0200 Subject: [PATCH 17/30] Convert Listing 7-17 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 01a8019d47..e0122e2b80 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -140,14 +140,13 @@ their scope. Listing 7-17 shows the code in Listing 7-11 with `use` in the root module changed to `pub use`. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-17/src/lib.rs}} ``` -Listing 7-17: Making a name available for any code to use -from a new scope with `pub use` + Before this change, external code would have to call the `add_to_waitlist` function by using the path From be0f5f9e0197906bc55ceea01c3eb9e6c907f2bd Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:32:35 +0200 Subject: [PATCH 18/30] Convert unnamed listing to `` I am unsure whether this `` will work properly due to no number being associated with it. @chriskrycho , since you implemented the pre-processor, could you please comment? (Sorry if there is a way that I could have checked this myself, I am unsure how to build the book. I'm just editing in plain-text and crossing my fingers, hope the whole thing doesn't come crumbling down when it's built.) --- src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index e0122e2b80..011ea5bbec 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -179,12 +179,14 @@ added this line to *Cargo.toml*: * ch14-03-cargo-workspaces.md --> -Filename: Cargo.toml + ```toml {{#include ../listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml:9:}} ``` + + Adding `rand` as a dependency in *Cargo.toml* tells Cargo to download the `rand` package and any dependencies from [crates.io](https://crates.io/) and make `rand` available to our project. From fbaee3d031c4d6e49a29fbd27e49f2a391591934 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:38:34 +0200 Subject: [PATCH 19/30] Converted another unnamed listing to `` (chapter 7.4) --- src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 011ea5bbec..bc0fa91880 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -226,12 +226,14 @@ each item on its own line can take up a lot of vertical space in our files. For example, these two `use` statements we had in the guessing game in Listing 2-4 bring items from `std` into scope: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/src/main.rs:here}} ``` + + Instead, we can use nested paths to bring the same items into scope in one line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that From de599ba6e143c06d72311b4bf72bf19982b709d6 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:41:32 +0200 Subject: [PATCH 20/30] Convert Listing 7-18 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index bc0fa91880..867ba0e332 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -239,14 +239,13 @@ line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that differ, as shown in Listing 7-18. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-18/src/main.rs:here}} ``` -Listing 7-18: Specifying a nested path to bring multiple -items with the same prefix into scope + In bigger programs, bringing many items into scope from the same crate or module using nested paths can reduce the number of separate `use` statements From 68a4499c5e3adfc7799cb51185bff5b5b7017676 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:44:27 +0200 Subject: [PATCH 21/30] Convert Listing 7-19 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 867ba0e332..cd0d3b9615 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -256,14 +256,13 @@ two `use` statements that share a subpath. For example, Listing 7-19 shows two `use` statements: one that brings `std::io` into scope and one that brings `std::io::Write` into scope. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-19/src/lib.rs}} ``` -Listing 7-19: Two `use` statements where one is a subpath -of the other + The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in From 3ae0b411494388144a1e5e557d5a6fed9fbefa46 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:46:22 +0200 Subject: [PATCH 22/30] Convert Listing 7-20 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index cd0d3b9615..aaf7713e95 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -268,14 +268,13 @@ The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in the nested path, as shown in Listing 7-20. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-20/src/lib.rs}} ``` -Listing 7-20: Combining the paths in Listing 7-19 into -one `use` statement + This line brings `std::io` and `std::io::Write` into scope. From 2c1ebb142eca8346cefe999c6da76bee9feb529d Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:49:13 +0200 Subject: [PATCH 23/30] Convert Listing 7-21 to `` --- src/ch07-05-separating-modules-into-different-files.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index b4cbcdbeda..c4a7805b97 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -16,14 +16,13 @@ the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code shown in Listing 7-21. Note that this won’t compile until we create the *src/front_of_house.rs* file in Listing 7-22. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/lib.rs}} ``` -Listing 7-21: Declaring the `front_of_house` module whose -body will be in *src/front_of_house.rs* + Next, place the code that was in the curly brackets into a new file named *src/front_of_house.rs*, as shown in Listing 7-22. The compiler knows to look From f294ad722ef975bac6d2eb1be836c59882f6f03a Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:51:53 +0200 Subject: [PATCH 24/30] Convert Listing 7-22 to `` --- src/ch07-05-separating-modules-into-different-files.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index c4a7805b97..26ab046fd6 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -29,14 +29,13 @@ Next, place the code that was in the curly brackets into a new file named in this file because it came across the module declaration in the crate root with the name `front_of_house`. -Filename: src/front_of_house.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/front_of_house.rs}} ``` -Listing 7-22: Definitions inside the `front_of_house` -module in *src/front_of_house.rs* + Note that you only need to load a file using a `mod` declaration *once* in your module tree. Once the compiler knows the file is part of the project (and knows From 50ad3cff2a248bbb043a55c9f586b4dc1e536283 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:55:00 +0200 Subject: [PATCH 25/30] Converted unnamed listing to `` (Chapter 7.5, 1/2) --- src/ch07-05-separating-modules-into-different-files.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index 26ab046fd6..f3788598ab 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -54,12 +54,14 @@ named for its ancestors in the module tree, in this case *src/front_of_house*. To start moving `hosting`, we change *src/front_of_house.rs* to contain only the declaration of the `hosting` module: -Filename: src/front_of_house.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/no-listing-02-extracting-hosting/src/front_of_house.rs}} ``` + + Then we create a *src/front_of_house* directory and a *hosting.rs* file to contain the definitions made in the `hosting` module: From 1d1b40c1157fb24ad0a721da44ce3320579e5952 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:57:22 +0200 Subject: [PATCH 26/30] Converted unnamed listing to `` (Chapter 7.5, 2/2) --- src/ch07-05-separating-modules-into-different-files.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index f3788598ab..2952e4b156 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -65,12 +65,14 @@ the declaration of the `hosting` module: Then we create a *src/front_of_house* directory and a *hosting.rs* file to contain the definitions made in the `hosting` module: -Filename: src/front_of_house/hosting.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/no-listing-02-extracting-hosting/src/front_of_house/hosting.rs}} ``` + + If we instead put *hosting.rs* in the *src* directory, the compiler would expect the *hosting.rs* code to be in a `hosting` module declared in the crate root, and not declared as a child of the `front_of_house` module. The From c521d2d4e498ae89174db8349774fe36d8042a1e Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 10:21:11 +0200 Subject: [PATCH 27/30] Chapter 7 - Wrap all ``s to comply with the virtual 80 character limit More infos and concerns can be found in the equivalent commit, in the chapter 6 PR. --- ...ng-modules-to-control-scope-and-privacy.md | 3 +- ...referring-to-an-item-in-the-module-tree.md | 25 +++++++++++----- ...g-paths-into-scope-with-the-use-keyword.md | 30 ++++++++++++------- ...separating-modules-into-different-files.md | 6 ++-- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index 0a711f9e6e..87ed1ee9e9 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -114,7 +114,8 @@ restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to define some modules and function signatures; this code is the front of house section. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-01/src/lib.rs}} diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index da07d9fd83..6931dd314d 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -29,7 +29,8 @@ The `eat_at_restaurant` function is part of our library crate’s public API, so we mark it with the `pub` keyword. In the [“Exposing Paths with the `pub` Keyword”][pub] section, we’ll go into more detail about `pub`. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-03/src/lib.rs}} @@ -69,7 +70,8 @@ each other. Let’s try to compile Listing 7-3 and find out why it won’t compile yet! The errors we get are shown in Listing 7-4. -+ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-03/output.txt}} @@ -105,7 +107,8 @@ private. We want the `eat_at_restaurant` function in the parent module to have access to the `add_to_waitlist` function in the child module, so we mark the `hosting` module with the `pub` keyword, as shown in Listing 7-5. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-05/src/lib.rs}} @@ -116,7 +119,8 @@ access to the `add_to_waitlist` function in the child module, so we mark the Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. -+ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-05/output.txt}} @@ -140,7 +144,9 @@ modules. Let’s also make the `add_to_waitlist` function public by adding the `pub` keyword before its definition, as in Listing 7-7. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs}} @@ -214,7 +220,8 @@ function `fix_incorrect_order` defined in the `back_of_house` module calls the function `deliver_order` defined in the parent module by specifying the path to `deliver_order`, starting with `super`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-08/src/lib.rs}} @@ -244,7 +251,8 @@ comes with a meal, but the chef decides which fruit accompanies the meal based on what’s in season and in stock. The available fruit changes quickly, so customers can’t choose the fruit or even see which fruit they’ll get. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs}} @@ -268,7 +276,8 @@ have such a function, we couldn’t create an instance of `Breakfast` in In contrast, if we make an enum public, all of its variants are then public. We only need the `pub` before the `enum` keyword, as shown in Listing 7-10. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-10/src/lib.rs}} diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index aaf7713e95..3de3ec1ad2 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -12,7 +12,8 @@ scope of the `eat_at_restaurant` function so we only have to specify `hosting::add_to_waitlist` to call the `add_to_waitlist` function in `eat_at_restaurant`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-11/src/lib.rs}} @@ -31,7 +32,8 @@ Note that `use` only creates the shortcut for the particular scope in which the child module named `customer`, which is then a different scope than the `use` statement, so the function body won’t compile. -+ ```rust,noplayground,test_harness,does_not_compile,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-12/src/lib.rs}} @@ -58,7 +60,8 @@ crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in `eat_at_restaurant`, rather than specifying the `use` path all the way out to the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-13/src/lib.rs}} @@ -79,7 +82,8 @@ it’s idiomatic to specify the full path. Listing 7-14 shows the idiomatic way to bring the standard library’s `HashMap` struct into the scope of a binary crate. -+ ```rust {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-14/src/main.rs}} @@ -95,7 +99,8 @@ into scope with `use` statements, because Rust doesn’t allow that. Listing 7-1 shows how to bring two `Result` types into scope that have the same name but different parent modules, and how to refer to them. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-15/src/lib.rs:here}} @@ -115,7 +120,8 @@ into the same scope with `use`: after the path, we can specify `as` and a new local name, or *alias*, for the type. Listing 7-16 shows another way to write the code in Listing 7-15 by renaming one of the two `Result` types using `as`. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-16/src/lib.rs:here}} @@ -140,7 +146,8 @@ their scope. Listing 7-17 shows the code in Listing 7-11 with `use` in the root module changed to `pub use`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-17/src/lib.rs}} @@ -239,7 +246,8 @@ line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that differ, as shown in Listing 7-18. -+ ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-18/src/main.rs:here}} @@ -256,7 +264,8 @@ two `use` statements that share a subpath. For example, Listing 7-19 shows two `use` statements: one that brings `std::io` into scope and one that brings `std::io::Write` into scope. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-19/src/lib.rs}} @@ -268,7 +277,8 @@ The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in the nested path, as shown in Listing 7-20. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-20/src/lib.rs}} diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index 2952e4b156..d0881a5767 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -16,7 +16,8 @@ the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code shown in Listing 7-21. Note that this won’t compile until we create the *src/front_of_house.rs* file in Listing 7-22. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/lib.rs}} @@ -29,7 +30,8 @@ Next, place the code that was in the curly brackets into a new file named in this file because it came across the module declaration in the crate root with the name `front_of_house`. -+ ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/front_of_house.rs}} From cfd25e798de551307a4af50e7444a05b2a648cfc Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 12:09:08 +0200 Subject: [PATCH 28/30] Convert unnamed `` (Chapter 7.2) --- src/ch07-02-defining-modules-to-control-scope-and-privacy.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index 87ed1ee9e9..ff37d5aebf 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -63,12 +63,14 @@ backyard The crate root file in this case is *src/main.rs*, and it contains: -Filename: src/main.rs + ```rust,noplayground,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/quick-reference-example/src/main.rs}} ``` + + The `pub mod garden;` line tells the compiler to include the code it finds in *src/garden.rs*, which is: From b69404ef002dbfa9c3ec29b27f6be30aec6a17f5 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 12:09:46 +0200 Subject: [PATCH 29/30] Convert unnamed `` (Chapter 7.2) --- src/ch07-02-defining-modules-to-control-scope-and-privacy.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index ff37d5aebf..cfab7cc36b 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -74,12 +74,14 @@ The crate root file in this case is *src/main.rs*, and it contains: The `pub mod garden;` line tells the compiler to include the code it finds in *src/garden.rs*, which is: -Filename: src/garden.rs + ```rust,noplayground,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/quick-reference-example/src/garden.rs}} ``` + + Here, `pub mod vegetables;` means the code in *src/garden/vegetables.rs* is included too. That code is: From d5a89d9db5fd3de8609c73208915bed14b2739ff Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 15 Oct 2024 07:11:40 -0600 Subject: [PATCH 30/30] Back out "Chapter 7 - Wrap all ``s to comply with the virtual 80 character limit" This backs out commit c521d2d4e498ae89174db8349774fe36d8042a1e. --- ...ng-modules-to-control-scope-and-privacy.md | 3 +- ...referring-to-an-item-in-the-module-tree.md | 25 +++++----------- ...g-paths-into-scope-with-the-use-keyword.md | 30 +++++++------------ ...separating-modules-into-different-files.md | 6 ++-- 4 files changed, 21 insertions(+), 43 deletions(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index cfab7cc36b..c1afe4c15a 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -118,8 +118,7 @@ restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to define some modules and function signatures; this code is the front of house section. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-01/src/lib.rs}} diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 6931dd314d..da07d9fd83 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -29,8 +29,7 @@ The `eat_at_restaurant` function is part of our library crate’s public API, so we mark it with the `pub` keyword. In the [“Exposing Paths with the `pub` Keyword”][pub] section, we’ll go into more detail about `pub`. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-03/src/lib.rs}} @@ -70,8 +69,7 @@ each other. Let’s try to compile Listing 7-3 and find out why it won’t compile yet! The errors we get are shown in Listing 7-4. -+ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-03/output.txt}} @@ -107,8 +105,7 @@ private. We want the `eat_at_restaurant` function in the parent module to have access to the `add_to_waitlist` function in the child module, so we mark the `hosting` module with the `pub` keyword, as shown in Listing 7-5. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-05/src/lib.rs}} @@ -119,8 +116,7 @@ module as `pub` to use it from `eat_at_restaurant`"> Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. -+ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-05/output.txt}} @@ -144,9 +140,7 @@ modules. Let’s also make the `add_to_waitlist` function public by adding the `pub` keyword before its definition, as in Listing 7-7. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs}} @@ -220,8 +214,7 @@ function `fix_incorrect_order` defined in the `back_of_house` module calls the function `deliver_order` defined in the parent module by specifying the path to `deliver_order`, starting with `super`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-08/src/lib.rs}} @@ -251,8 +244,7 @@ comes with a meal, but the chef decides which fruit accompanies the meal based on what’s in season and in stock. The available fruit changes quickly, so customers can’t choose the fruit or even see which fruit they’ll get. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs}} @@ -276,8 +268,7 @@ have such a function, we couldn’t create an instance of `Breakfast` in In contrast, if we make an enum public, all of its variants are then public. We only need the `pub` before the `enum` keyword, as shown in Listing 7-10. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-10/src/lib.rs}} diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 3de3ec1ad2..aaf7713e95 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -12,8 +12,7 @@ scope of the `eat_at_restaurant` function so we only have to specify `hosting::add_to_waitlist` to call the `add_to_waitlist` function in `eat_at_restaurant`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-11/src/lib.rs}} @@ -32,8 +31,7 @@ Note that `use` only creates the shortcut for the particular scope in which the child module named `customer`, which is then a different scope than the `use` statement, so the function body won’t compile. -+ ```rust,noplayground,test_harness,does_not_compile,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-12/src/lib.rs}} @@ -60,8 +58,7 @@ crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in `eat_at_restaurant`, rather than specifying the `use` path all the way out to the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-13/src/lib.rs}} @@ -82,8 +79,7 @@ it’s idiomatic to specify the full path. Listing 7-14 shows the idiomatic way to bring the standard library’s `HashMap` struct into the scope of a binary crate. -+ ```rust {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-14/src/main.rs}} @@ -99,8 +95,7 @@ into scope with `use` statements, because Rust doesn’t allow that. Listing 7-1 shows how to bring two `Result` types into scope that have the same name but different parent modules, and how to refer to them. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-15/src/lib.rs:here}} @@ -120,8 +115,7 @@ into the same scope with `use`: after the path, we can specify `as` and a new local name, or *alias*, for the type. Listing 7-16 shows another way to write the code in Listing 7-15 by renaming one of the two `Result` types using `as`. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-16/src/lib.rs:here}} @@ -146,8 +140,7 @@ their scope. Listing 7-17 shows the code in Listing 7-11 with `use` in the root module changed to `pub use`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-17/src/lib.rs}} @@ -246,8 +239,7 @@ line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that differ, as shown in Listing 7-18. -+ ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-18/src/main.rs:here}} @@ -264,8 +256,7 @@ two `use` statements that share a subpath. For example, Listing 7-19 shows two `use` statements: one that brings `std::io` into scope and one that brings `std::io::Write` into scope. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-19/src/lib.rs}} @@ -277,8 +268,7 @@ The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in the nested path, as shown in Listing 7-20. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-20/src/lib.rs}} diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index d0881a5767..2952e4b156 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -16,8 +16,7 @@ the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code shown in Listing 7-21. Note that this won’t compile until we create the *src/front_of_house.rs* file in Listing 7-22. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/lib.rs}} @@ -30,8 +29,7 @@ Next, place the code that was in the curly brackets into a new file named in this file because it came across the module declaration in the crate root with the name `front_of_house`. -+ ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/front_of_house.rs}}