I have the following file structure:
- src
- function.rs
- main.rs
- misc_helpers.rs
- method.rs
In the main.rs I do the following:
mod misc_helpers;
mod method;
mod function;
because I use functions from these modules. Now in method.rs I use functions from misc_helpers.rs and function.rs. To include these files I want to use mod (just like in main.rs) but it gives me the error:
file not found for module `misc_helpers`
help: to create the module `misc_helpers`, create file "src/method/misc_helpers.rs"
I've found that I have 2 solutions:
(Solution 1) src/method.rs
use super::misc_helpers;
use super::function::*;
(Solution 2) src/method.rs
#[path = "misc_helpers.rs"] mod misc_helpers;
#[path = "function.rs"] mod function;
use function::*;
So I have 3 questions:
- Why in the
method.rsI can't justmodmy way out without usingpath(like inmain.rs)? I guess thatmain.rsshould be considered as acargomodule (i.e. root module) and I can only usemodto include "child" modules (deeper in the module hierarchy) and not "parent" ones? - Why does
use super::work (inmethod.rs) even though I don't include the files? - What's the better solution (1 or 2) and why?