You should use conditional compilation attributes:
#[cfg(feature = "debugging")] macro_rules! log { () => { println!("Debugging") } } #[cfg(not(feature = "debugging"))] macro_rules! log { () => { } } fn main() { log!(); }
Here you can use Cargo "features" to provide a compile-time argument that switches the debugging implementation.
However, in this case there is no need to use macros:
#[cfg(feature = "debugging")] fn log() { println!("Debugging") } #[cfg(not(feature = "debugging"))] fn log() {} fn main() { log(); }
I would very much trust the optimizer to create the same code in this case.
source share