包含模块Rust

时间:2017-02-04 22:30:01

标签: rust

我的问题与How to include module from another file from the same project?非常相似,因为我尝试将mod导入我的 main.rs 并使用它,除了mod有一个私人和公共功能。

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();
}

我收到以下构建错误:

unresolved name sys::get_cpu_stats

由于这是我的第一个Rust项目,我确信我做错了什么,但我不确定那是什么东西。

1 个答案:

答案 0 :(得分:1)

sys.rs 更改为:

C:\fakepath\ART.pdf

因为文件 sys.rs 已经是模块范围。我本可以写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 }

感谢6月在IRC!