When to use extern create crateName, mod crateName or just use crateName::SomeFromCrate

In my Cargo.toml I have:

log = "*"

then in my .rs file I have:

use log::{debug, error, info, log_enabled, Level};

And all is well and dandy and it works.
Then, I add into Cargo.toml

term = "*"

and this time I cannot (or can I?) do just:

use term::Something

Instead I have to do:

extern crate term;


Do you or don't you get a compilation error without extern crate term? I have no problem compiling without it. Make sure you have edition = "2018" in Cargo.toml, which -- among other things -- allows you to omit extern crate in almost all circumstances (the exceptions are crates that come with the standard library: std, alloc).

Edition differences aside, these two snippets always do the same thing, unless you have another item named foo in scope:

use crate_name::foo;
// ...
fn main() {
// ...
fn main() {

mod name does something completely different: it declares a module in the current crate.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.