rust - How to "use another-file" in rust? Module with hyphens in it
问题描述
Using another_file
with underscore in as word separators works fine in Rust.
How do i use hyphens instead (another-file.rs
)?
// another-file.rs
pub fn method() { }
// lib.rs
use another_file; // <-- ERROR can not find another_file.rs
another_file::method();
解决方案
您必须显式声明模块并提供其路径:
#[path="../path/to/another-file.rs"]
mod another_file;
use another_file;
然而,这并不常见,我不会推荐它。只需坚持使用 snake_case 作为模块名称即可。
推荐阅读
- python - Tensorflow-gpu 在拟合模型时不使用 GPU
- xml - 如何使用 XSLT 添加子元素?
- flutter - 摆脱 Flutter 中的黄黑线
- python - 如何在 Tensorflow 1.x 中的训练期间打印值
- windows - 在 winfoms 中添加广告组成员
- java - 上下文中 Spark 作业的实际运行时间
- firebase - Cloud_firestore 0.14.* 升级后 Firestore 模拟器无法正常工作
- python - 访问字典中的字典 | 雅虎财经导入
- spring - Spring WebFlux 相当于 getFirstHeader
- python - Python日期格式转换