Consider you have a module my_mod
with a pub function my_func
. You can’t use
this function in your crate (or outside your crate) until you include your module using mod my_mod
statement.
After you include your module, you can use your function like that:
mod my_mod;
...
my_mod::my_func(...)
...
You can’t use my_mod::my_func
statement if you don’t include your module somewhere in your crate.
Sometimes it is better to import frequently used definitions:
mod my_mod;
use my_mod::my_func;
Now, if you want to use your function, you can just write:
my_func(...);
You can also re-export definitions of sub-modules (or even other crates!) using pub use
statement.
If you working with other crates imported through Cargo.toml
(by listing them as dependencies), you may import definitions from these crates using only use
statement.