I'm trying to create a project that builds both a lib and a bin, but I'm having problems getting the compiler to recognize a module when building.
Here's my project tree:
Here's the error I get when I have the module in the src dir:
error[E0583]: file not found for module `hasher`
--> src\lib.rs:1:9
|
1 | pub mod hasher;
| ^^^^^^
|
= help: name the file either lib\hasher.rs or lib\hasher\mod.rs inside the directory "src"
So I've done what the compiler suggests and move the file to lib\hasher like so:
Now I get the following error:
error[E0583]: file not found for module `hasher`
--> src/lib.rs:1:9
|
1 | pub mod hasher;
| ^^^^^^
|
= help: name the file either hasher.rs or hasher\mod.rs inside the directory "src"
I have no idea how to get this to compile. Any advice?
Here's the contents of my Cargo.toml if that matters:
[package]
name = "tool"
version = "0.1.0"
authors = ["Jeramy<none@none.com>"]
edition = "2018"
[dependencies]
crypto-hash = "0.3.3"
filebuffer = "0.4.0"
[lib]
name = "hasher"
path = "src/lib.rs"
[[bin]]
name = "tool"
path = "src/main.rs"
@carols10cents, I had the externs in main.rs and pub mod lib; I did what you suggested, removing the stuff from the config and naming the file src/hasher.rs and it still failed the same way.
Moving the externs to lib.rs and removing pub mod lib fixed the issue, although I don't understand why. I also don't understand why I was getting the error messages and why they would change to back and forth when I followed the compilers instructions.
lib is a starting point for a library. You can't reuse it as a module. The whole library will be compiled and made available to you in the binary automatically.