Skip to content

Potentially incorrect text in Chapter 7.4: Bringing Paths into Scope with the use Keyword #3447

@Mindstormer619

Description

@Mindstormer619
  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • 7.4
    • Before this change, external code would have to call
  • I have checked the latest main branch to see if this has already been fixed, in this file:

URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html#bringing-paths-into-scope-with-the-use-keyword

Description of the problem:

The problem is in the segment: Before this change, external code would have to call the add_to_waitlist function by using the path restaurant::front_of_house::hosting::add_to_waitlist(). External code cannot call the add_to_waitlist() function because the front_of_house module is not marked pub. Code to demonstrate:

lib.rs

mod front_of_house {
    pub mod hosting {
        pub fn add_to_waitlist() {}
    }
}

use crate::front_of_house::hosting;

pub fn eat_at_restaurant() {
    hosting::add_to_waitlist();
}

main.rs

fn main() {
    backyard::front_of_house::hosting::add_to_waitlist(); // does not compile
}

Error:

minds@Zero-Requiem MINGW64 /d/Workspace/Rust/RustBook/backyard (main)
$ cargo c
    Checking backyard v0.1.0 (D:\Workspace\Rust\RustBook\backyard)
error[E0603]: module `front_of_house` is private
 --> src\main.rs:2:15
  |
2 |     backyard::front_of_house::hosting::add_to_waitlist();
  |               ^^^^^^^^^^^^^^ private module
  |
note: the module `front_of_house` is defined here
 --> d:\Workspace\Rust\RustBook\backyard\src\lib.rs:1:1
  |
1 | mod front_of_house {
  | ^^^^^^^^^^^^^^^^^^

Suggested fix:

pub needs to be added before mod front_of_house.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions