I want to make a macro which finds arguments whose type are pointer, and
copy their values on the stack, then call the function with the copied values.
After the function retunes, it copies back to the original variable.
Below is an example.
let var: usize = 0x123;
my_macro!(my_func(&mut var as *mut usize));
macro_rules my_macro {
($f:ident( *mut $var:tt, $($tail:tt)*)) => {
let temp_var = *var;
$f(&temp_var, $($tail:tt)*);
*var = temp_var;
};
}
I can handle it with a single pointer argument when it is the first argument of the function. However, I can't handle it when there are multiple pointer arguments and their order is random. I was able to use the incremental TT munchers to figure out which argument is a pointer, but I can only find pointers.