amin
amin

Reputation: 3852

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();

Upvotes: 12

Views: 2721

Answers (1)

mcarton
mcarton

Reputation: 30021

You will have to explicitly declare the module and provide its path:

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

use another_file;

However this is not common, and I wouldn't recommand it. Just stick with snake_case for module names.

Upvotes: 19

Related Questions