macro_use and extern crate
#[macro_use]
extern crate diesel;
I find this snippet of code in the diesel tutorial document. What is the “macro_use” attribute? What does it mean “extern crate”?
macro_use
The first thing I noticed is this statement is always one line up of the “extern crate” statement. These lines of code is used like a pair.
The attribute imports macros in the crates. For example, the above snippet means, in this scope, we can use macros that are defined in diesel crates.
extern crate
In a nutshell, it is equivalent to the “use” statement. It indicates that you want to link against an external library and brings the top-level crate name into scope.
Leave a comment