【发布时间】:2013-06-27 22:57:47
【问题描述】:
我试图弄清楚如何在 Rust 中编译多文件 crate,但我不断收到编译错误。
我有想要导入 crate thing.rs 的文件:
mod asdf {
pub enum stuff {
One,
Two,
Three
}
}
还有我的 crate 文件 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
显然,关于模块、板条箱和使用工作的方式很简单,我只是没有得到。我的理解是那个 mod 的东西;对于同一目录或 extern mod 中的文件;对于库路径上的库,导致目标文件被链接。然后使用将允许您将模块的部分导入到当前文件、函数或模块中。这似乎适用于核心库中的内容。
这是 0.6 版的 rust 编译器。
【问题讨论】:
标签: rust