I don't understand mod
or use
; I suppose that mod
will import files into the project and use
will use them.
I have a project with this hierarchy:
.
|-- Cargo.lock
|-- Cargo.toml
|-- src
| |-- display.rs
| |-- list.rs
| |-- main.rs
| |-- parser.rs
| |-- sort.rs
Why do I need use
in list.rs and not in main.rs? I use the function sorting()
and print_files()
in list.rs like I use the function parse()
and listing()
in main.rs.
main.rs
mod parser; // Ok
mod list; // Ok
mod sort; // Ok
mod display; // Ok
// use parser;// The name `parser` is defined multiple times
fn main() {
parser::parse();
list::listing();
}
list.rs
//mod sort; // file not found in module `sort`
//mod display; // file not found in module `display`
use sort; // Ok
use display; // Ok
pub fn listing() {
parcours_elements();
sort::sorting();
display::print_files();
}
fn parcours_elements() {
}
sort.rs
pub fn sorting() {
}
display.rs
pub fn print_files() {
}