Search code examples
rustrust-macros

What does #[macro_use] before an extern crate statement mean?


In Rust, I sometimes see #[macro_use] before an extern crate statement:

#[macro_use]
extern crate gotham_derive;

What does this do compared to not having #[macro_use]?

extern crate gotham_derive;

Solution

  • It means to import ("use") the macros from the crate.

    As of Rust 1.30, this syntax is no longer generally needed and you can use the standard use keyword instead.

    Review the macros chapter from the first edition of The Rust Programming Language for more detail.