首页 > 解决方案 > 同一目录中文件的模块错误未找到 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 关键字,它只包含公共函数。这让我难倒了一段时间。谢谢您的帮助。

标签: importmodulerust

解决方案


推荐阅读