Is it possible to make a Rust macro that can access both the name and value of a variable passed as a parameter?
let my_variable: i32 = 5;
printvar!(my_variable); // => to print "my_variable = 5"
For example with C macros we can use the #
operator:
#include <stdio.h>
#define PRINT_VAR(x) printf("%s = %d\n", #x, x);
int main() {
int my_variable = 5;
PRINT_VAR(my_variable);
}
$ ./a.out
my_variable = 5