在同一目录中找不到用于模块错误的Rust文件

时间:2019-08-21 13:30:38

标签: import module rust

Rust无法通过声明找到本地文件。我在src中具有以下文件结构:

| main.rs
| lib.rs
| test.rs
| prog.rs
| file.rs

在main.rs中,我有

extern crate cratename;
mod prog;

use cratename::file1::File1;
...
prog::function() // This works
...
#[cfg(test)]
mod test;

我在lib.rs中拥有

pub mod file1;

在test.rs中,我有

extern crate cratename
use cratename::file1::File1;
mod prog;
#[test]
...
prog::function() // This does not work
...

我不断收到错误消息

error[E0583]: file not found for module `prog`

我尝试将声明放在lib.rs中,但这没有用。我已经尝试过其他许多与main.rs一起涉及此声明的排列,但没有一个起作用。如果有帮助,则prog.rs不包含结构,也不使用mod关键字,它仅包含公共函数。这让我难过了一阵子。谢谢您的帮助。

0 个答案:

没有答案