modular-bitfield icon indicating copy to clipboard operation
modular-bitfield copied to clipboard

Feature Request: Ability to specify default value for field

Open ohunter opened this issue 10 months ago • 0 comments

I have a struct where one flag has to be 1 no matter what. With the current implementation I have to do something like this no matter what which doesn't really feel ergonomic:

#[bitfield]
struct Foo {
  pub foo: bool,
  pub field_has_to_be_there: bool,
  pub bar: bool,
  #[skip] __: B5,
}

let foo = Foo::new().with_field_has_to_be_there(true)....;

I'd like for something like this to be possible:

#[bitfield]
struct Foo {
  pub foo: bool,
  #[default(true), skip] __: bool,
  pub bar: bool,
  #[skip] __: B5,
}

let foo = Foo::new()....;

ohunter avatar Apr 19 '24 07:04 ohunter