Robbepop / modular-bitfield

Macro to generate bitfields for structs that allow for modular use of enums.
Apache License 2.0
155 stars 40 forks source link

Feature Request: Ability to specify default value for field #105

Open ohunter opened 2 months ago

ohunter commented 2 months ago

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()....;