deliberate.codes

Weblog of Marco N. - a software guy in data. I build with AI.

Rust's dbg! macro preserves expression value

The dbg! macro in Rust not only prints debug output but also returns the value, making it perfect for inline debugging:

let result = dbg!(expensive_calculation());

This prints [src/main.rs:1] expensive_calculation() = 42 and assigns 42 to result. No need to split into separate lines for debugging.