Do you put `#[macro_use]` in it's own line or inline with `extern crate foo`?


#1

Do you put #[macro_use] in it’s own line or inline with extern crate foo?

Do you write this:

extern crate alpha;
extern crate beta;
#[macro_use] extern crate gamma;
extern crate delta;

or this?

extern crate alpha;
extern crate beta;
#[macro_use]
extern crate gamma;
extern crate delta;

#2

I like it inlined personally, but rustfmt puts it on its own line by default. Since I use format on save, I don’t bother fighting it :stuck_out_tongue:


#3
#[macro_use] extern crate gamma;
#[macro_use] extern crate epsilon;

extern crate alpha;
extern crate beta;
extern crate delta;

Two reasons: first, it keeps things nice and regular so they’re easier to visually scan. Secondly, macro crates get “hoisted” by the compiler to the top of the scope, so putting them anywhere else is a dirty, filthy lie. I mean, at least until macros are no longer lexically order dependent…


#4

I did not know that. Good point :+1:


#5

I usually put it on its own line, and then I try to group macro_used crates so that they appear first, so that the import structure looks more regular:

#[macro_use]
extern crate clap;
#[macro_use]
extern crate magnet_derive;
#[macro_use]
extern crate bitflags;
extern crate serde_json;
extern crate ron;
extern crate rand;