In Rust, I have the following folder structure:
├── Cargo.toml
└── src
├── bin
│ └── main.rs
└── lib.rs
This is as recommended in this answer.
This is the (relevant) contents of the Cargo.toml
file:
[package]
name = "devinit"
...
And this is the contents of my lib.rs
file:
pub mod testmod {
pub fn testfunc() {
println!("Hello world");
}
}
When trying to use the function testfunc()
in main.rs
, I can refer to it by specifying its scope:
fn main() {
devinit::testmod::testfunc();
}
This compiles and executes successfully. However, if I were to actually 'use' it, as seen below...
use devinit::testmod::testfunc;
fn main() {
testfunc();
}
...the compilation fails. The following code fails to compile with the error 'failed to resolve: maybe a missing crate `devinit`?'
Why is this happening? Looking at the aforementioned answer's author's project (linked in previous edits of the answer), the structure seems to be the same...
I'm pretty new to Rust, so maybe I missed something?