Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

Rust import error

I have a Rust project made by cargo init:

dir
 |-src
    |-main.rs
    |-settings.rs
    |-functions.rs

I have in settings.rs:

use ::functions;

but at compilation I get an error:

error[E0432]: unresolved import `functions`
--> src/settings.rs:3:5
  |
3 | use ::functions;
  |     ^^^^^^^^^^^ no `functions` in the root
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your comments, you state:

I don't want to use [mod functions] because it will search for settings/functions.rs, and it is not i want to

Have you tried that? Assuming you've declared the module correctly ... this is exactly what you want.

main.rs:

mod functions;
mod settings;

fn main() { 
    ...
}

settings.rs:

use functions;

pub fn something() {
    functions::some_function_here();
}

If this does not work .. then there is something missing from your problem description.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...