我正在尝试从位于另一个文件中的模块中调用一个公共函数,我使用完整路径进行调用,但rustc仍然抱怨"未解决的名称"。
a.rs
pub mod b;
fn main() {
b::f()
}
b.rs
pub mod b {
pub fn f(){
println!("Hello World!");
}
}
编译
$ rustc a.rs
a.rs:3:5: 3:9 error: unresolved name `b::f`.
当我将该模块移动到木箱的主文件时,一切都正常。
one_file.rs
pub mod b {
pub fn f(){
println!("Hello World!");
}
}
fn main() {
b::f()
}
这两种方式不应该是等效的吗?我是做错了什么,还是rustc有bug?