Skip to content

Example in "Separating Modules into Different Files" doesn't look to need main function #2930

@lucascr91

Description

@lucascr91

In the section "Separating Modules into Different Files", authors show how to separate modules in many files. At the end of the example, the user folder structure looks like this:

├── Cargo.lock
├── Cargo.toml
├── src
│   ├── front_of_house
│   │   └── hosting.rs
│   ├── front_of_house.rs
│   └── lib.rs

Copying the code snippets for each file using the copy icon gives:

lib.rs

mod front_of_house;

pub use crate::front_of_house::hosting;

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

front_of_house.rs

pub mod hosting;

front_of_house/hosting.rs

#![allow(unused)]
fn main() {
pub fn add_to_waitlist() {}
}

Using this snippets, cargo check fails:

error[E0425]: cannot find function `add_to_waitlist` in module `hosting`
 --> src/lib.rs:6:14
  |
6 |     hosting::add_to_waitlist();
  |              ^^^^^^^^^^^^^^^ not found in `hosting`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
error: could not compile `restaurant`

To learn more, run the command again with --verbose.

It works using:

front_of_house/hosting.rs

pub fn add_to_waitlist() {}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions