rust - 如何在同一级别包含文件/模块?
问题描述
我正在使用具有以下文件结构的 Rust 2018:
src/main.rs
src/types.rs
src/compute.rs
types.rs
包含pub struct Entity {}
.
我没有问题,包括types
和:compute
main.rs
mod types;
mod compute;
我想在types
里面导入compute.rs
:
mod types;
// or
pub mod types;
我得到:
file not found for module types
我试图遵循版本指南中的路径清晰但没有成功。
这些示例从不引用不是来自或的同一级别导入main.rs
lib.rs
我尝试使用以下方法指定路径:
#[path = "types.rs"] mod types;
然后我得到这个错误:
expected type `compute::types::Entity`
found type `types::Entity`
似乎它正在重新定义types
我的模块中的模块compute
。
我不能使用use
关键字,因为它不是外部 crate。
我通过示例查看了 Rust 中的文件层次结构,但没有相同级别的导入。
我试图避免mod.rs
在 Rust 2015 中出现类似情况。
有没有办法进行同级别的导入?
我的文件结构有问题吗?
什么文件结构会更好?
解决方案
推荐阅读
- r - 在 R 中按唯一日期而不是观察值来训练和测试拆分
- python - 返回_compile(pattern,flags).findall(string)时出错TypeError:预期的字符串或类似字节的对象
- .net - 如何在没有 .net SDK 的情况下构建 .Net SDK
- css - flex 0 0 的引导解决方案
- c++ - 在模板中使用非模板嵌套类
- stl - 具有对象数据的容器上的 C++17 并行算法
- perl - sed 相当于 perl -pe
- excel - 使用 Checkbox .OnAction 时无法将字符串参数传递给 Sub
- python - 为什么 Pandas DataFrame 的第一次操作耗时最长?
- facebook - 使用 Facebook 页面插件的“参数 href 是必需的”错误