I'm looking to create a Rust macro that can do what this does in C.
#define V(a,b,c,d) 0x##a##b##c##d
Which when called with:
V(7B,B0,B0,CB)
Will simply have the following hexadecimal number placed in the code at compile time:
0x7BaB0bB0cCDd
Trying something like this:
macro_rules! gen_hex_num {
($a:expr , $b:expr , $c:expr , $d:expr) => (
0x($a)a($b)b($c)c($d)d
)
}
Produces an error:
error: macro expansion ignores token `a` and any following
--> src/main.rs:3:16
|
3 | 0x($a)a($b)b($c)c($d)d
| ^
|
note: caused by the macro expansion here; the usage of `gen_hex_num!` is
likely invalid in expression context
Documentation and other questions don't seem to cover this scenario.