I'm trying to understand how to properly setup imports, with two goals in mind:
- Every script should be compilable using
rustc
- Building via cargo is supported swell.
With absolute paths it seems to work. I cannot get it to work with relative paths. However it seems wrong to use absolute paths.
Whats the correct way to handle imports?
Lets take two examples into account:
1. Example
src
├── main.rs
├── root
│ └── nested.rs
└── root.rs
abs paths
// main.rs:
#[path="root/nested.rs"]
mod nested
#[path="root.rs"]
mod root
// root.rs:
#[path="root/nested.rs"]
mod nested
rel paths
// main.rs:
mod root;
use crate::root::nested;
// root.rs --\> cannot be compiled using `rustc`.
pub mod nested;
2. Example
src
├── main.rs
├── notnested.rs
└── root.rs
abs paths
// main.rs:
#[path="notnested.rs"]
mod notnested
#[path="root.rs"]
mod root
// root.rs:
#[path="notnested.rs"]
mod notnested
rel paths
// main.rs:
mod root
mod notnested
// root.rs --\> cannot be compiled using `rustc`.
use crate::notnested;