Currently, we expose set_XYZ methods that return void, so if you want to populate a bitfield you have to have a mutable variable:
let mut example = Example::new();
example.set_a(true);
example.set_b(0b0001_1111_1111_u16);
example.set_c(42_u16);
example.set_d(DeliveryMode::Startup);
example.set_e(1);
What if there were a with_XYZ method which returned the bitfield object itself:
let example = Example::new()
.with_a(true)
.with_b(0b0001_1111_1111_u16)
.with_c(42_u16)
.with_d(DeliveryMode::Startup)
.with_e(1);
?
I'm thinking a signature like:
fn set_a(self, value: bool) -> Self;
And, I guess, a with_a_checked which returns Result<Self>:
let example = Example::new()
.with_a_checked(true)?
.with_b_checked(...)?;
I think this would fit better in a closure-based modification API (similar to the API svd2rust provides):
Currently, we expose
set_XYZ
methods that return void, so if you want to populate a bitfield you have to have a mutable variable:What if there were a
with_XYZ
method which returned the bitfield object itself:?
I'm thinking a signature like:
And, I guess, a
with_a_checked
which returnsResult<Self>
:I think this would fit better in a closure-based modification API (similar to the API svd2rust provides):
vs.
I can throw together a PR, but wanted to get thoughts first.