less than 1 minute read

#[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.

Answer from Stackoverflow

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.

Answer from Stackoverflow

Tags:

Categories:

Updated:

Leave a comment