Closed danlehmann closed 8 months ago
Another option would be to emit a warning on "default: 0x2" but instead ask to use a newer syntax, which then generates the new const DEFAULT?
I think the most sensible thing to do for now is to support both new()
and DEFAULT, but deprecate new().
This was merged a while ago
One of the thing that everyone has been confused about is that
default: 0x123
creates anew()
function.The problem is that
new()
looks pretty harmless and like the preferred way to create a bitfield. However, when using bitfields with hardware, the correct way is to read from hardware, modify and write-back. So it's pretty easy to write code that accidentally overwrites unrelated bits.Example: Let's assume we have a bitfield like this:
It is very easy to create a new bitfield like this:
let foo = MyBitfield::new()
This will set the bits of foo to the default value specified in the definition of MyBitfield, which is 0x2.
A much more obvious syntax would be this however:
let foo = MyBitfield::DEFAULT;
Of course, we can't just remove the current syntax as that would break clients. But we can make the switch gradually: