Are there any situations where extern crate
needs to be used in the 2021 (or 2018) edition, or is it there purely for backwards compatibility?
2 Likes
See:
(click here to see full thread)
2 Likes
extern crate
is still useful if you want to import all macros from a crate like
#[macro_use] // to bring `anyhow!`, `bail!` and `ensure!` into scope
extern crate Anyhow;
1 Like
I would not recommend that. It's much less clear than use
, and an artifact of old system.
2 Likes
As in the other thread, extern crate alloc;
is one use, as is #![no_std] #[cfg(feature = "std")] extern crate std;
.
One use that I don't see often mentioned is extern crate self as name
, which allows you to use ::name
in addition to ::crate
to refer to your own crate. This can be useful for e.g. macros, or even just for making internal code look more like external code.
9 Likes
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.