I need to generate setters and getters for my FFI code.
Is there a way I can append the variable name to the setter and getter function names in a macro? I tried stringify!($var + set)
but it generated a bunch of errors.
Is hiding it in a module for each variable the only way?
macro_rules! gen {
($var:ident: $type:ident) => {
pub fn set(new_val: $type) {
unsafe { $var = new_val; }
}
pub fn get() -> $type {
unsafe { $var }
}
}
}
gen!(myvar1: u32);
gen!(myvar2: i32);
For myvar1
the setter and getter would be myvar1_set
and myvar1_get
respectively.