我有以下代码:
pub mod a {
#[test]
pub fn test() {
println!("{:?}", std::fs::remove_file("Somefilehere"));
}
}
我编译这段代码时出现了错误:
error[E0433]: failed to resolve. Use of undeclared type or module `std`
--> src/main.rs:4:24
|
4 | println!("{}", std::fs::remove_file("Somefilehere"));
| ^^^ Use of undeclared type or module `std`
不过,移除内部模块并将其包含的代码单独编译却可以正常工作:
#[test]
pub fn test() {
println!("{:?}", std::fs::remove_file("Somefilehere"));
}
我在这里漏掉了什么?如果模块在单独的文件中,我会得到相同的错误:
main.rs
pub mod a;
a.rs
#[test]
pub fn test() {
println!("{:?}", std::fs::remove_file("Somefilehere"));
}
use std::io::fs
,然后调用例如fs::unlink
。 - Renato Zannon