diff --git a/src/ch07-01-mod-and-the-filesystem.md b/src/ch07-01-mod-and-the-filesystem.md index 38cb7acd2..e38ce0e33 100644 --- a/src/ch07-01-mod-and-the-filesystem.md +++ b/src/ch07-01-mod-and-the-filesystem.md @@ -15,8 +15,10 @@ $ cargo new communicator $ cd communicator ``` -You'll notice that Cargo generated `src/lib.rs` instead of `src/main.rs` for -us, and inside it we'll find this: +Notice that Cargo generated `src/lib.rs` instead of `src/main.rs` for us, and +inside it we'll find this: + +Filename: src/lib.rs ```rust #[cfg(test)] @@ -55,6 +57,8 @@ rather than `connect()`. You could have multiple modules, side-by-side. For example, if you wanted a `client` module: +Filename: src/lib.rs + ```rust mod network { fn connect() { @@ -72,6 +76,8 @@ Now we have a `network::connect` function and a `client::connect` function. And you can put modules inside of modules. If you wanted to have `client` be within `network`: +Filename: src/lib.rs + ```rust mod network { fn connect() { diff --git a/src/ch07-02-controlling-visibility-with-pub.md b/src/ch07-02-controlling-visibility-with-pub.md index a841488c6..eaf0a761e 100644 --- a/src/ch07-02-controlling-visibility-with-pub.md +++ b/src/ch07-02-controlling-visibility-with-pub.md @@ -208,6 +208,8 @@ Overall, these are the rules for item visibility: Let's look at a few more examples to get some practice. What if we had this code in a new project's `src/lib.rs`: +Filename: src/lib.rs + ```rust,ignore mod outermost { pub fn middle_function() {} diff --git a/src/ch07-03-importing-names-with-use.md b/src/ch07-03-importing-names-with-use.md index 462aa00b4..3030ba2dd 100644 --- a/src/ch07-03-importing-names-with-use.md +++ b/src/ch07-03-importing-names-with-use.md @@ -3,6 +3,8 @@ We've seen how we can call functions defined within a module by using the module name as part of the call, like this: +Filename: src/main.rs + ```rust pub mod a { pub mod series { @@ -21,6 +23,8 @@ However, referring to the fully qualified name can get quite lengthy, as we see in that example. To solve this issue, Rust has a keyword, `use`. It works like this: +Filename: src/main.rs + ```rust pub mod a { pub mod series { @@ -132,6 +136,8 @@ Since tests are for exercising the code within our library, let's try to call our `client::connect` function from this `it_works` function, even though we're not going to be checking any functionality right now: +Filename: src/lib.rs + ```rust #[cfg(test)] mod tests { @@ -193,6 +199,8 @@ instead of to the root module. For these reasons, in the `tests` module especially, `use super::something` is usually the way to go. So now our test looks like this: +Filename: src/lib.rs + ```rust #[cfg(test)] mod tests {