Is there a way of doing this?
self.mega_ultra_field = 100500;
print_expr_and_value!(self.mega_ultra_field);
Output:
self.mega_ultra_field 100500
Use dbg!
:
dbg!(self.mega_ultra_field);
[src/main.rs:16] self.mega_ultra_field = 100500
Use stringify!
:
macro_rules! print_expr_and_value {
($e:expr) => {
eprintln!("{} {}", stringify!($e), $e)
};
}
struct Foo {
mega_ultra_field: i32,
}
impl Foo {
fn bar(&mut self) {
self.mega_ultra_field = 100500;
print_expr_and_value!(self.mega_ultra_field);
dbg!(self.mega_ultra_field);
}
}
fn main() {
Foo {
mega_ultra_field: 0,
}
.bar();
}
self.mega_ultra_field 100500
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With