How to create doc tests for macros?


I am struggling to figure out how to nicely document my macros (in arrayref, in case you’re wondering). I’d love to have examples that serve as doc tests, but haven’t been able to figure out how to load the macros in the example code.

I’m afraid the scoping of macros is still a bit of a mystery to me, as is the behavior of cargo test, so it’s not surprising that this combination would lead to mysterious errors. Any suggestions?


You have to define your own main() function in the example, as far as I know, and then do #[macro_use] extern crate arrayref. You can look at how I did it in Rustful. (Note that lines that starts with # ... are hidden in the rendered docs)


Thanks so much, that does it precisely!