macro_rules! dev_only {
($($body:tt)*) => { ... };
}Expand description
Runs body only in a build that compiles in development diagnostics.
Expands to if DEV { body }. Because DEV is a const, a release build folds the branch
away and drops body with it, including any message strings and bookkeeping it alone
references.
body is type-checked in every mode. That is the point: a diagnostic that only compiles on
one profile rots, and the rot surfaces as a broken release build. The cost is that body may
not reference items that themselves exist only in a dev build.
Control flow escapes the block on one profile only. A return, ?, break, or continue
inside body runs in a dev build and is skipped entirely in a release build, so the
surrounding function must be correct when the block does nothing. Confine body to
diagnostics and their bookkeeping; if the enclosing function’s result depends on it, the
profiles disagree.
§Examples
use retroglyph_core::dev_only;
let sprite_px = (32, 32);
let cell_px = (16, 16);
dev_only!({
if sprite_px > cell_px {
warn_overflow(sprite_px, cell_px);
}
});The block form is not required; any statements work.
dev_only!(misses += 1;);