Skip to content

Commit 265e26f

Browse files
author
gaoyuan
committed
fix: prefix the actual file name if referenced listing is in another ch.md
1 parent 89ad502 commit 265e26f

33 files changed

+57
-57
lines changed

src/ch01-03-hello-cargo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn main() {
9898
```
9999

100100
Cargo has generated a “Hello, world!” program for you, just like the one we
101-
wrote in [Listing 1-1](#listing-1-1)! So far, the differences between our project and the
101+
wrote in [Listing 1-1](ch01-02-hello-world.md#listing-1-1)! So far, the differences between our project and the
102102
project Cargo generated are that Cargo placed the code in the _src_ directory
103103
and we have a _Cargo.toml_ configuration file in the top directory.
104104

src/ch04-02-references-and-borrowing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## References and Borrowing
22

3-
The issue with the tuple code in [Listing 4-5](#listing-4-5) is that we have to return the
3+
The issue with the tuple code in [Listing 4-5](ch04-01-what-is-ownership.md#listing-4-5) is that we have to return the
44
`String` to the calling function so we can still use the `String` after the
55
call to `calculate_length`, because the `String` was moved into
66
`calculate_length`. Instead, we can provide a reference to the `String` value.

src/ch06-03-if-let.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ runs code when the value matches one pattern and then ignores all other values.
4747
We can include an `else` with an `if let`. The block of code that goes with the
4848
`else` is the same as the block of code that would go with the `_` case in the
4949
`match` expression that is equivalent to the `if let` and `else`. Recall the
50-
`Coin` enum definition in [Listing 6-4](#listing-6-4), where the `Quarter` variant also held a
50+
`Coin` enum definition in [Listing 6-4](ch06-02-match.md#listing-6-4), where the `Quarter` variant also held a
5151
`UsState` value. If we wanted to count all non-quarter coins we see while also
5252
announcing the state of the quarters, we could do that with a `match`
5353
expression, like this:

src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A path can take two forms:
1515
Both absolute and relative paths are followed by one or more identifiers
1616
separated by double colons (`::`).
1717

18-
Returning to [Listing 7-1](#listing-7-1), say we want to call the `add_to_waitlist` function.
18+
Returning to [Listing 7-1](ch07-02-defining-modules-to-control-scope-and-privacy.md#listing-7-1), say we want to call the `add_to_waitlist` function.
1919
This is the same as asking: what’s the path of the `add_to_waitlist` function?
2020
[Listing 7-3](#listing-7-3) contains [Listing 7-1](#listing-7-1) with some of the modules and functions
2121
removed.

src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Bringing Paths into Scope with the `use` Keyword
22

33
Having to write out the paths to call functions can feel inconvenient and
4-
repetitive. In [Listing 7-7](#listing-7-7), whether we chose the absolute or relative path to
4+
repetitive. In [Listing 7-7](ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md#listing-7-7), whether we chose the absolute or relative path to
55
the `add_to_waitlist` function, every time we wanted to call `add_to_waitlist`
66
we had to specify `front_of_house` and `hosting` too. Fortunately, there’s a
77
way to simplify this process: we can create a shortcut to a path with the `use`
@@ -221,7 +221,7 @@ crate.
221221

222222
If we’re using multiple items defined in the same crate or same module, listing
223223
each item on its own line can take up a lot of vertical space in our files. For
224-
example, these two `use` statements we had in the guessing game in [Listing 2-4](#listing-2-4)
224+
example, these two `use` statements we had in the guessing game in [Listing 2-4](ch02-00-guessing-game-tutorial.md#listing-2-4)
225225
bring items from `std` into scope:
226226

227227
<Listing file-name="src/main.rs">

src/ch07-05-separating-modules-into-different-files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ So far, all the examples in this chapter defined multiple modules in one file.
44
When modules get large, you might want to move their definitions to a separate
55
file to make the code easier to navigate.
66

7-
For example, let’s start from the code in [Listing 7-17](#listing-7-17) that had multiple
7+
For example, let’s start from the code in [Listing 7-17](ch07-04-bringing-paths-into-scope-with-the-use-keyword.md#listing-7-17) that had multiple
88
restaurant modules. We’ll extract modules into files instead of having all the
99
modules defined in the crate root file. In this case, the crate root file is
1010
_src/lib.rs_, but this procedure also works with binary crates whose crate root

src/ch10-01-syntax.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function that uses generics.
2424

2525
</Listing>
2626

27-
The `largest_i32` function is the one we extracted in [Listing 10-3](#listing-10-3) that finds
27+
The `largest_i32` function is the one we extracted in [Listing 10-3](ch10-00-generics.md#listing-10-3) that finds
2828
the largest `i32` in a slice. The `largest_char` function finds the largest
2929
`char` in a slice. The function bodies have the same code, so let’s eliminate
3030
the duplication by introducing a generic type parameter in a single function.
@@ -179,7 +179,7 @@ The `Result` enum is generic over two types, `T` and `E`, and has two variants:
179179
`E`. This definition makes it convenient to use the `Result` enum anywhere we
180180
have an operation that might succeed (return a value of some type `T`) or fail
181181
(return an error of some type `E`). In fact, this is what we used to open a
182-
file in [Listing 9-3](#listing-9-3), where `T` was filled in with the type `std::fs::File` when
182+
file in [Listing 9-3](ch09-02-recoverable-errors-with-result.md#listing-9-3), where `T` was filled in with the type `std::fs::File` when
183183
the file was opened successfully and `E` was filled in with the type
184184
`std::io::Error` when there were problems opening the file.
185185

src/ch10-03-lifetime-syntax.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,10 @@ the `ImportantExcerpt` goes out of scope, so the reference in the
391391

392392
You’ve learned that every reference has a lifetime and that you need to specify
393393
lifetime parameters for functions or structs that use references. However, we
394-
had a function in [Listing 4-9](#listing-4-9), shown again in [Listing 10-25](#listing-10-25), that compiled
394+
had a function in [Listing 4-9](ch04-03-slices.md#listing-4-9), shown again in [Listing 10-25](#listing-10-25), that compiled
395395
without lifetime annotations.
396396

397-
<Listing number="10-25" file-name="src/lib.rs" caption="A function we defined in [Listing 4-9](#listing-4-9) that compiled without lifetime annotations, even though the parameter and return type are references">
397+
<Listing number="10-25" file-name="src/lib.rs" caption="A function we defined in [Listing 4-9](ch04-03-slices.md#listing-4-9) that compiled without lifetime annotations, even though the parameter and return type are references">
398398

399399
```rust
400400
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-25/src/main.rs:here}}
@@ -516,7 +516,7 @@ annotate lifetimes in method signatures very often.
516516
### Lifetime Annotations in Method Definitions
517517

518518
When we implement methods on a struct with lifetimes, we use the same syntax as
519-
that of generic type parameters, as shown in [Listing 10-11](#listing-10-11). Where we declare and
519+
that of generic type parameters, as shown in [Listing 10-11](ch10-01-syntax.md#listing-10-11). Where we declare and
520520
use the lifetime parameters depends on whether they’re related to the struct
521521
fields or the method parameters and return values.
522522

src/ch11-01-writing-tests.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ to ensure that some condition in a test evaluates to `true`. We give the
185185
`assert!` macro calls `panic!` to cause the test to fail. Using the `assert!`
186186
macro helps us check that our code is functioning in the way we intend.
187187

188-
In Chapter 5, [Listing 5-15](#listing-5-15), we used a `Rectangle` struct and a `can_hold`
188+
In Chapter 5, [Listing 5-15](ch05-03-method-syntax.md#listing-5-15), we used a `Rectangle` struct and a `can_hold`
189189
method, which are repeated here in [Listing 11-5](#listing-11-5). Let’s put this code in the
190190
_src/lib.rs_ file, then write some tests for it using the `assert!` macro.
191191

@@ -344,7 +344,7 @@ the standard library types implement these traits. For structs and enums that
344344
you define yourself, you’ll need to implement `PartialEq` to assert equality of
345345
those types. You’ll also need to implement `Debug` to print the values when the
346346
assertion fails. Because both traits are derivable traits, as mentioned in
347-
[Listing 5-12](#listing-5-12) in Chapter 5, this is usually as straightforward as adding the
347+
[Listing 5-12](ch05-02-example-structs.md#listing-5-12) in Chapter 5, this is usually as straightforward as adding the
348348
`#[derive(PartialEq, Debug)]` annotation to your struct or enum definition. See
349349
Appendix C, [“Derivable Traits,”][derivable-traits]<!-- ignore --> for more
350350
details about these and other derivable traits.
@@ -413,7 +413,7 @@ debug what happened instead of what we were expecting to happen.
413413

414414
In addition to checking return values, it’s important to check that our code
415415
handles error conditions as we expect. For example, consider the `Guess` type
416-
that we created in Chapter 9, [Listing 9-13](#listing-9-13). Other code that uses `Guess`
416+
that we created in Chapter 9, [Listing 9-13](ch09-03-to-panic-or-not-to-panic.md#listing-9-13). Other code that uses `Guess`
417417
depends on the guarantee that `Guess` instances will contain only values
418418
between 1 and 100. We can write a test that ensures that attempting to create a
419419
`Guess` instance with a value outside that range panics.

src/ch11-03-test-organization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function from the `it_adds_two` test in _tests/integration_test.rs_:
225225
```
226226

227227
Note that the `mod common;` declaration is the same as the module declaration
228-
we demonstrated in [Listing 7-21](#listing-7-21). Then, in the test function, we can call the
228+
we demonstrated in [Listing 7-21](ch07-05-separating-modules-into-different-files.md#listing-7-21). Then, in the test function, we can call the
229229
`common::setup()` function.
230230

231231
#### Integration Tests for Binary Crates

0 commit comments

Comments
 (0)