replace_token!() { /* proc-macro */ }
Expand description
Replaces all occurences of a given single token with another single token.
Takes arguments in the order replace_token!{needle, replacement, code to search}
. You may use any kind of brackets.
§Panics
At compile time, if the arguments cannot be correctly parsed.
§Examples
Replaces all plus signs with minus signs:
replace_token!{+, -,
let x = (1 + 2) + 3;
}
assert_eq!(x, -4);
Replaces the identifier MY_ARRAY
with an array literal
replace_token!{MY_ARRAY, [8, 0],
let x = MY_ARRAY;
}
assert_eq!(x, [8, 0]);