Skip to content

Commit

Permalink
Back out "Chapter 7 - Wrap all <Listing>s to comply with the virtua…
Browse files Browse the repository at this point in the history
…l 80 character limit"

This backs out commit c521d2d.
  • Loading branch information
chriskrycho committed Oct 15, 2024
1 parent b69404e commit d5a89d9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 43 deletions.
3 changes: 1 addition & 2 deletions src/ch07-02-defining-modules-to-control-scope-and-privacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Listing number="7-1" file-name="src/lib.rs" caption="A `front_of_house` module
containing other modules that then contain functions">
<Listing number="7-1" file-name="src/lib.rs" caption="A `front_of_house` module containing other modules that then contain functions">

```rust,noplayground
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-01/src/lib.rs}}
Expand Down
25 changes: 8 additions & 17 deletions src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]<!-- ignore --> section, we’ll go into more detail about `pub`.

<Listing number="7-3" file-name="src/lib.rs" caption="Calling the
`add_to_waitlist` function using absolute and relative paths">
<Listing number="7-3" file-name="src/lib.rs" caption="Calling the `add_to_waitlist` function using absolute and relative paths">

```rust,ignore,does_not_compile
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-03/src/lib.rs}}
Expand Down Expand Up @@ -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.

<Listing number="7-4" caption="Compiler errors from building the code in
Listing 7-3">
<Listing number="7-4" caption="Compiler errors from building the code in Listing 7-3">

```console
{{#include ../listings/ch07-managing-growing-projects/listing-07-03/output.txt}}
Expand Down Expand Up @@ -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.

<Listing number="7-5" file-name="src/lib.rs" caption="Declaring the `hosting`
module as `pub` to use it from `eat_at_restaurant`">
<Listing number="7-5" file-name="src/lib.rs" caption="Declaring the `hosting` module as `pub` to use it from `eat_at_restaurant`">

```rust,ignore,does_not_compile
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-05/src/lib.rs}}
Expand All @@ -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.

<Listing number="7-6" caption="Compiler errors from building the code in
Listing 7-5">
<Listing number="7-6" caption="Compiler errors from building the code in Listing 7-5">

```console
{{#include ../listings/ch07-managing-growing-projects/listing-07-05/output.txt}}
Expand All @@ -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.

<Listing number="7-7" file-name="src/lib.rs" caption="Adding the `pub` keyword
to `mod hosting` and `fn add_to_waitlist` lets us call the function from
`eat_at_restaurant`">
<Listing number="7-7" file-name="src/lib.rs" caption="Adding the `pub` keyword to `mod hosting` and `fn add_to_waitlist` lets us call the function from `eat_at_restaurant`">

```rust,noplayground,test_harness
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs}}
Expand Down Expand Up @@ -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`.

<Listing number="7-8" file-name="src/lib.rs" caption="Calling a function using
a relative path starting with `super`">
<Listing number="7-8" file-name="src/lib.rs" caption="Calling a function using a relative path starting with `super`">

```rust,noplayground,test_harness
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-08/src/lib.rs}}
Expand Down Expand Up @@ -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.

<Listing number="7-9" file-name="src/lib.rs" caption="A struct with some public
fields and some private fields">
<Listing number="7-9" file-name="src/lib.rs" caption="A struct with some public fields and some private fields">

```rust,noplayground
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs}}
Expand All @@ -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.

<Listing number="7-10" file-name="src/lib.rs" caption="Designating an enum as
public makes all its variants public">
<Listing number="7-10" file-name="src/lib.rs" caption="Designating an enum as public makes all its variants public">

```rust,noplayground
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-10/src/lib.rs}}
Expand Down
30 changes: 10 additions & 20 deletions src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

<Listing number="7-11" file-name="src/lib.rs" caption="Bringing a module into
scope with `use`">
<Listing number="7-11" file-name="src/lib.rs" caption="Bringing a module into scope with `use`">

```rust,noplayground,test_harness
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-11/src/lib.rs}}
Expand All @@ -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.

<Listing number="7-12" file-name="src/lib.rs" caption="A `use` statement only
applies in the scope it’s in">
<Listing number="7-12" file-name="src/lib.rs" caption="A `use` statement only applies in the scope it’s in">

```rust,noplayground,test_harness,does_not_compile,ignore
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-12/src/lib.rs}}
Expand All @@ -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.

<Listing number="7-13" file-name="src/lib.rs" caption="Bringing the
`add_to_waitlist` function into scope with `use`, which is unidiomatic">
<Listing number="7-13" file-name="src/lib.rs" caption="Bringing the `add_to_waitlist` function into scope with `use`, which is unidiomatic">

```rust,noplayground,test_harness
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-13/src/lib.rs}}
Expand All @@ -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.

<Listing number="7-14" file-name="src/main.rs" caption="Bringing `HashMap` into
scope in an idiomatic way">
<Listing number="7-14" file-name="src/main.rs" caption="Bringing `HashMap` into scope in an idiomatic way">

```rust
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-14/src/main.rs}}
Expand All @@ -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.

<Listing number="7-15" file-name="src/lib.rs" caption="Bringing two types with
the same name into the same scope requires using their parent modules.">
<Listing number="7-15" file-name="src/lib.rs" caption="Bringing two types with the same name into the same scope requires using their parent modules.">

```rust,noplayground
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-15/src/lib.rs:here}}
Expand All @@ -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`.

<Listing number="7-16" file-name="src/lib.rs" caption="Renaming a type when
it’s brought into scope with the `as` keyword">
<Listing number="7-16" file-name="src/lib.rs" caption="Renaming a type when it’s brought into scope with the `as` keyword">

```rust,noplayground
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-16/src/lib.rs:here}}
Expand All @@ -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`.

<Listing number="7-17" file-name="src/lib.rs" caption="Making a name available
for any code to use from a new scope with `pub use`">
<Listing number="7-17" file-name="src/lib.rs" caption="Making a name available for any code to use from a new scope with `pub use`">

```rust,noplayground,test_harness
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-17/src/lib.rs}}
Expand Down Expand Up @@ -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.

<Listing number="7-18" file-name="src/main.rs" caption="Specifying a nested
path to bring multiple items with the same prefix into scope">
<Listing number="7-18" file-name="src/main.rs" caption="Specifying a nested path to bring multiple items with the same prefix into scope">

```rust,ignore
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-18/src/main.rs:here}}
Expand All @@ -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.

<Listing number="7-19" file-name="src/lib.rs" caption="Two `use` statements
where one is a subpath of the other">
<Listing number="7-19" file-name="src/lib.rs" caption="Two `use` statements where one is a subpath of the other">

```rust,noplayground
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-19/src/lib.rs}}
Expand All @@ -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.

<Listing number="7-20" file-name="src/lib.rs" caption="Combining the paths in
Listing 7-19 into one `use` statement">
<Listing number="7-20" file-name="src/lib.rs" caption="Combining the paths in Listing 7-19 into one `use` statement">

```rust,noplayground
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-20/src/lib.rs}}
Expand Down
6 changes: 2 additions & 4 deletions src/ch07-05-separating-modules-into-different-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Listing number="7-21" file-name="src/lib.rs" caption="Declaring the
`front_of_house` module whose body will be in *src/front_of_house.rs*">
<Listing number="7-21" file-name="src/lib.rs" caption="Declaring the `front_of_house` module whose body will be in *src/front_of_house.rs*">

```rust,ignore,does_not_compile
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/lib.rs}}
Expand All @@ -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`.

<Listing number="7-22" file-name="src/front_of_house.rs" caption="Definitions
inside the `front_of_house` module in *src/front_of_house.rs*">
<Listing number="7-22" file-name="src/front_of_house.rs" caption="Definitions inside the `front_of_house` module in *src/front_of_house.rs*">

```rust,ignore
{{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/front_of_house.rs}}
Expand Down

0 comments on commit d5a89d9

Please sign in to comment.