No more extern crateextern crate
You no longer need to write extern crateextern crate
to import a crate into your project. Before:
// Rust 2015
extern crate futures;
mod submodulefoo {
use futures::Future;
}
// Rust 2018
mod submodulefoo {
use futures::Future;
}
One other use for extern crate was to import macros; that's no longer needed. In your Rust 2015, you would have written:
// Rust 2015
#[macro_use]
extern crate bar;log;
fn main() {
bazerror!("oops");
}
// Rust 2018
use barlog::baz;error;
fn main() {
bazerror!("oops");
}
extern crate futures as f;fut;
use futures as f;fut;
use self::ffut::Future;
There's one exception to this rule:Sysroot Crates
There's one exception to this rule, and that's the "sysroot" crates. These are the crates distributed with Rust itself. We'd eventually like to remove the requirement for extern crate for them as wellFor now, but it hasn't shipped yet.
You'llyou still need to use extern crateextern crate
for these crates:
proc_macro
Additionally, you would need to use it for:
core
std
However, extern crate std;std
is already implicit, and with #![no_std]
, extern crate core
; is are already implicit. You'll only, so it is very rare that you will need these in highly specialized situationsto declare them manually.
// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
If there's no edition`edition
key, Cargo will default to Rust 2015. But in this case, we've chosen 2018, and so our code is compiling with Rust 2018! Thanks to @KevinReid for pointing this out