O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Debugging macros

Before we head over to macro keywords and building our own macros, let's take a look at what to do when our macros don't work.

The first technique is to ask the compiler to show us the code after the macro expansion has been done. Here's our macro that either takes nothing or a block. As a bonus, let's see what println! really becomes:

// expand-macro.rs macro_rules! meep {     () => (nothing);    ($block:block) => ( make($block); ); } fn main() {     meep!();     meep!({silly; things});     println!("Just to show how fun println! really gets"); } 

The expansion is requested from the compiler by using the parameter --pretty expanded. This is an unstable feature, but at the time of writing this book, it is still kind of supported by the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required