Modules is a strangely difficult thing to grasp in Rust. I have shuffled things around quite a bit in my project to familiarize myself with all the different ways of using/moding. However, it still is not clear to me even after reading the docs on modules. I have used the compiler to help me up to this point but I am stuck on how to import my functions into my test file. My directory looks like this:
src
├── channels.rs
├── data
│ ├── channels-all-time.json
│ ├── members-all-time.json
│ └── overview-all-time.json
├── main.rs
├── members.rs
└── util.rs
tests
├── channels.rs
└── data
├── channels-all-time.json
└── members-all-time.json
My helper functions exist inside of mod
s inside of members.rs, util.rs, and channels.rs. I can't for the life of me figure out how to get them into tests though. When I try to import my module by doing use channels
in my channels.rs
file under tests
I get this error:
error[E0432]: unresolved import `channels`
--> tests/channels.rs:1:5
|
1 | use channels;
| ^^^^^^^^ no `channels` external crate
When I use main
I get a slightly better error.
warning: unused import: `main`
--> tests/channels.rs:1:5
|
1 | use main;
| ^^^^
|
= note: `#[warn(unused_imports)]` on by default
This gives me a little hope thinking that because I put mod channels
in main.rs
, maybe that means I can import them from there so then I put use main::channels
. But to no avail:
error[E0432]: unresolved import `main`
--> tests/channels.rs:1:5
|
1 | use main::channels;
| ^^^^ use of undeclared type or module `main`
Any help on this would be appreciated. I know I am missing something but I can't quite wrap my head around it.