Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch07 - remove note regarding use and relative path #1820

Merged
merged 1 commit into from
Sep 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 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 @@ -41,10 +41,9 @@ root, `hosting` is now a valid name in that scope, just as though the `hosting`
module had been defined in the crate root. Paths brought into scope with `use`
also check privacy, like any other paths.

Specifying a relative path with `use` is slightly different. Instead of
starting from a name in the current scope, we must start the path given to
`use` with the keyword `self`. Listing 7-12 shows how to specify a relative
path to get the same behavior as in Listing 7-11.
You can also bring an item into scope with `use` and a relative path. Listing
7-12 shows how to specify a relative path to get the same behavior as in
Listing 7-11.

<span class="filename">Filename: src/lib.rs</span>

Expand All @@ -55,7 +54,7 @@ mod front_of_house {
}
}

use self::front_of_house::hosting;
use front_of_house::hosting;

pub fn eat_at_restaurant() {
hosting::add_to_waitlist();
Expand All @@ -66,10 +65,7 @@ pub fn eat_at_restaurant() {
```

<span class="caption">Listing 7-12: Bringing a module into scope with `use` and
a relative path starting with `self`</span>

Note that using `self` in this way might not be necessary in the future; it’s
an inconsistency in the language that Rust developers are working to eliminate.
a relative path</span>

### Creating Idiomatic `use` Paths

Expand Down