I was sitting typing a ton of repetitive code and thought - I should write a macro to do this. Then I realized that what I need cannot be done with the type of macro that I know how to write.
Here is what I need (it's describing the location of bits in a u16):
const XXX_OFF: u16 = n;
const XXX: Word = 1 << XXX_OFF;
e.g.
const RTS_OFF: u16 = 0;
const RTS: Word = 1 << RTS_OFF;
const CTS_OFF: u16 = 3;
const CTS: Word = 1 << CTS_OFF;
// ...
declaring the offset and generating a bitmask for each named bit in a u16
.
As you can see the only things that change are XXX
and n
. Is there anyway I could automate this? It would be trivial in C. I wonder if there is some form of template driven proc macro out there. Or if there is another way of achieving the same thing. Maybe I have to go learn how to write proc macros.