【发布时间】:2023-01-12 06:34:05
【问题描述】:
我有三个文件:
// a.rs
struct MyThing {
}
// b.rs
mod a;
struct That {
mything: &a::MyThing;
}
// main.rs
mod a;
mod b;
fn main() {
let thing= a::MyThing{};
let that= b::That{myThing: &thing};
}
我得到的 a.rs 的编译错误是:
找不到模块
b的文件 帮助:创建模块b,创建文件“src/a/b.rs”或“src/a/b/mod.rs”我以为我需要
mod a;以便我可以访问a.rs中的模块,但看起来因为mod b;在main.rs中,b.rs中的mod a;是相对于b解释的。 ..或者其他的东西。如何使用另一个
.rs文件?
【问题讨论】:
标签: file rust module rust-crates