我正在尝试弄清楚如何在Rust中编译多文件crate,但是我一直收到编译错误。
我有一个想要导入到crate的文件thing.rs:
mod asdf {
pub enum stuff {
One,
Two,
Three
}
}
我的货箱文件test.rc:
mod thing;
use thing::asdf::*;
fn main(){
}
当我运行rust build test.rc时,我会得到以下结果:
test.rc:3:0: 3:19 error: `use` and `extern mod` declarations must precede items
test.rc:3 use thing::asdf::*;
^~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
很明显,模块、箱子和use的工作原理很简单,但我仍然不能理解。我的理解是,在相同目录下使用mod something; 或在库路径上使用extern mod something; 会导致链接对象文件。然后,使用use可以将模块的部分导入当前文件、函数或模块中。这对核心库中的内容似乎是有效的。
这是使用Rust编译器版本0.6时的情况。