首页 > 解决方案 > 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();

标签: rust

解决方案


您必须显式声明模块并提供其路径

#[path="../path/to/another-file.rs"]
mod another_file;

use another_file;

然而,这并不常见,我不会推荐它。只需坚持使用 snake_case 作为模块名称即可。


推荐阅读