I'm sure, this problem has been raised 1000 times already, but I think the whole way of module import/usage is not water proof.
I'm having a beginners project creating an executable. main.rs
is the main source, including several other mods by mod <name>;
. All these files exist in the crate root, ./src
directory.
That works fine. Now I thought it would be a good idea to put 99% of my functionality into a lib in order to allow binding with other projects.
So I created a ./src/lib.rs
and took over all the mod declarations formerly contained in ./src/main.rs
by removing them the same time from main.rs
.
Basically my lib.rs looked like so after this op:
mod opts;
mod constants;
mod config;
mod tools;
mod df_imports;
mod api;
pub fn test() {
}
I was able to compile the project and as desired an executable and a library was created.
Now - of course I need to use my library from the main app, so I inserted this into main.rs
, which right now does not look different from this:
mod lib;
use lib::test;
fn main() {
test::test();
}
The only fact to include mod lib;
in main.rs is sufficient to generate tons of errors of the same kind, I don't even have to use lib::test;
or to call a function.
error[E0583]: file not found for module `opts`
--> src/lib.rs:1:1
|
1 | mod opts;
| ^^^^^^^^^
|
= help: to create the module `opts`, create file "src/lib/opts.rs"
error[E0583]: file not found for module `constants`
--> src/lib.rs:2:1
|
2 | mod constants;
| ^^^^^^^^^^^^^^
|
= help: to create the module `constants`, create file "src/lib/constants.rs"
error[E0583]: file not found for module `config`
--> src/lib.rs:3:1
|
3 | mod config;
| ^^^^^^^^^^^
|
= help: to create the module `config`, create file "src/lib/config.rs"
error[E0583]: file not found for module `tools`
--> src/lib.rs:4:1
|
4 | mod tools;
| ^^^^^^^^^^
|
= help: to create the module `tools`, create file "src/lib/tools.rs"
error[E0583]: file not found for module `df_imports`
--> src/lib.rs:5:1
|
5 | mod df_imports;
| ^^^^^^^^^^^^^^^
|
= help: to create the module `df_imports`, create file "src/lib/df_imports.rs"
error[E0583]: file not found for module `api`
--> src/lib.rs:6:1
|
6 | mod api;
| ^^^^^^^^
|
= help: to create the module `api`, create file "src/lib/api.rs"
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0583`.
error: could not compile `dragonfly2`.
To learn more, run the command again with --verbose.
I have no clue, why this happens. I started a new project from scratch and did the same operations, there everything worked...
What chances do I have to come after that? Do I really have to move all my modules to src/lib/
(which is not existent yet?)
PS: After having done what was suggested (moving all the mod files to src/lib) I'm now getting the reverse error:
warning: 60 warnings emitted
error[E0583]: file not found for module
opts
--> src/lib.rs:1:1
|
1 | mod opts;
| ^^^^^^^^^
|
= help: to create the moduleopts
, create file "src/lib/opts.rs"error[E0583]: file not found for module
constants
--> src/lib.rs:2:1
|
2 | mod constants;
| ^^^^^^^^^^^^^^
|
= help: to create the moduleconstants
, create file "src/lib/constants.rs"error[E0583]: file not found for module
config
--> src/lib.rs:3:1
|
3 | mod config;
| ^^^^^^^^^^^
|
= help: to create the moduleconfig
, create file "src/lib/config.rs"error[E0583]: file not found for module
tools
--> src/lib.rs:4:1
|
4 | mod tools;
| ^^^^^^^^^^
|
= help: to create the moduletools
, create file "src/lib/tools.rs"error[E0583]: file not found for module
df_imports
--> src/lib.rs:5:1
|
5 | mod df_imports;
| ^^^^^^^^^^^^^^^
|
= help: to create the moduledf_imports
, create file "src/lib/df_imports.rs"error[E0583]: file not found for module
api
--> src/lib.rs:6:1
|
6 | mod api;
| ^^^^^^^^
|
= help: to create the moduleapi
, create file "src/lib/api.rs"error: aborting due to 6 previous errors
For more information about this error, try
rustc --explain E0583
.
error: could not compiledragonfly2
.To learn more, run the command again with --verbose.
~/Documents/dragonfly2rust $
~/Documents/dragonfly2rust $
~/Documents/dragonfly2rust $ cargo build
Compiling dragonfly2 v0.1.6 (/Users/decades/Documents/dragonfly2rust)
error: couldn't read src/constants.rs: No such file or directory (os error 2)
--> build.rs:4:1
|
4 | mod constants;
| ^^^^^^^^^^^^^^error: aborting due to previous error
error: could not compile
dragonfly2
.To learn more, run the command again with --verbose.
~/Documents/dragonfly2rust $ cargo build
Compiling dragonfly2 v0.1.6 (/Users/decades/Documents/dragonfly2rust)
error[E0583]: file not found for moduleopts
--> src/lib.rs:1:1
|
1 | mod opts;
| ^^^^^^^^^
|
= help: to create the moduleopts
, create file "src/opts.rs"error[E0583]: file not found for module
constants
--> src/lib.rs:2:1
|
2 | mod constants;
| ^^^^^^^^^^^^^^
|
= help: to create the moduleconstants
, create file "src/constants.rs"error[E0583]: file not found for module
config
--> src/lib.rs:3:1
|
3 | mod config;
| ^^^^^^^^^^^
|
= help: to create the moduleconfig
, create file "src/config.rs"error[E0583]: file not found for module
tools
--> src/lib.rs:4:1
|
4 | mod tools;
| ^^^^^^^^^^
|
= help: to create the moduletools
, create file "src/tools.rs"error[E0583]: file not found for module
df_imports
--> src/lib.rs:5:1
|
5 | mod df_imports;
| ^^^^^^^^^^^^^^^
|
= help: to create the moduledf_imports
, create file "src/df_imports.rs"error[E0583]: file not found for module
api
--> src/lib.rs:6:1
|
6 | mod api;
| ^^^^^^^^
|
= help: to create the moduleapi
, create file "src/api.rs"error: aborting due to 6 previous errors
For more information about this error, try
rustc --explain E0583
.
error: could not compiledragonfly2
.To learn more, run the command again with --verbose.
Does that make any sense?