November 2017
Intermediate to advanced
264 pages
5h 45m
English
As we demonstrated at the end of the Adding external crates to a project section, loading all macros from an external crate is done by preceding the extern crate abc with the attribute #[macro_use]. If you only need the macros mac1 and mac2, you can write this:
#[macro_use(mac1, mac2)] extern crate abc;
If the attribute is not present, no macros are loaded from abc.
Moreover, inside the abc module, only macros defined with the #[macro_export] attribute can be loaded in another module.
To distinguish macros with the same name in different modules, use the $crate variable in the macro. Within the code of a macro imported from a crate, abc, the special macro variable $crate will expand to ::abc.
Read now
Unlock full access