another_file在 Rust 中使用下划线作为单词分隔符工作正常。
我如何改用连字符 ( another-file.rs)?
// another-file.rs
pub fn method() { }
Run Code Online (Sandbox Code Playgroud)
// lib.rs
use another_file; // <-- ERROR can not find another_file.rs
another_file::method();
Run Code Online (Sandbox Code Playgroud)
您必须显式声明模块并提供其路径:
#[path="../path/to/another-file.rs"]
mod another_file;
use another_file;
Run Code Online (Sandbox Code Playgroud)
然而,这并不常见,我不会推荐它。只需坚持使用 snake_case 作为模块名称。
| 归档时间: |
|
| 查看次数: |
446 次 |
| 最近记录: |