Gyscos
Gyscos

Reputation: 1842

How do I properly write macro documentation if the macro is defined in a module?

I defined a macro in a module, and it works fine. Now, I'm trying to document said macro with an example. Apparently, I need to manually specify the crate line to ask for macros:

/// ```
/// # #[macro_use] extern crate foo;
/// // Some code
/// ```

However, I now get an error saying:

error: an `extern crate` loading macros must be at the crate root

Apparently the example code is loaded in the macro's module, and does not seem compatible with macro_use...

I can't believe everyone writes macros directly in the root module... right?

Upvotes: 4

Views: 547

Answers (1)

Gyscos
Gyscos

Reputation: 1842

Well adding a main function did the trick. My example code did not need to run anything (just compile) so I didn't even bother adding a main function, but apparently adding it puts the code in a virtual "crate root", and it accepts the macro_use. Yay!

So what I did is just add :

/// # fn main() { }

Upvotes: 2

Related Questions