Previously, we abused Default for the initial state of things we deserialize into.
For Rust structs, there is no realistic way to avoid that.
But for Rust bitfields, there absolutely is a way to avoid that, and it's a good idea especially since we want to be allowed to only specify one member of the bitfield in the JSON, and the Default is not necessarily instantiating an empty bitfield. That means we would erroneously start with an instance with one flag set (for example Normal), and then additionally set another flag (for example Critical) in addition. That's probably not what the user intended.
This PR introduces a fn builder that's used by the deserializers (and the builder pattern) instead of Default.
Then, Default can actually have nice user-visible defaults that are not empty.
Previously, we abused
Default
for the initial state of things we deserialize into.For Rust
struct
s, there is no realistic way to avoid that.But for Rust bitfields, there absolutely is a way to avoid that, and it's a good idea especially since we want to be allowed to only specify one member of the bitfield in the JSON, and the
Default
is not necessarily instantiating an empty bitfield. That means we would erroneously start with an instance with one flag set (for exampleNormal
), and then additionally set another flag (for exampleCritical
) in addition. That's probably not what the user intended.This PR introduces a fn
builder
that's used by the deserializers (and the builder pattern) instead ofDefault
.Then,
Default
can actually have nice user-visible defaults that are not empty.