1

My question is pretty similar to How to include module from another file from the same project?, in that I am trying to import a mod into my main.rs and use it, except my mod has a private and public function.

sys.rs

mod sys {
    fn read_num_lines(file: File, num_lines: i32) -> bool {
        //do bar with foo
    }
    pub fn get_cpu_stats() {
        //call read_num_lines
        //doo foo
    }
}

main.rs

mod sys;
fn main() {
    sys::get_cpu_stats();
}

I get the following build error:

unresolved name sys::get_cpu_stats

Since this is my first Rust project, I'm sure I'm doing something wrong, but am unsure as to what that something is.

Community
  • 1
  • 1
Turtle
  • 1,369
  • 1
  • 17
  • 32

1 Answers1

1

Change sys.rs to:

fn read_num_lines(file: File, num_lines: i32) -> bool {
    //do bar with foo
}
pub fn get_cpu_stats() {
    //call read_num_lines
    //doo foo
}

since the file sys.rs is already a module scope. I could have also written sys::sys::get_cpu_stats();

Thanks to June in IRC!

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Turtle
  • 1,369
  • 1
  • 17
  • 32