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

Silence "associated function is never used" warnings? #59

Closed Skirmisher closed 3 years ago

Skirmisher commented 3 years ago

I've noticed that generated functions on a #[bitfield] struct will cause warnings when not used, such as this:

warning: associated function is never used: `new`
  --> src/scsi2sd_config.rs:34:1
   |
34 | #[derive(BinRead, Default)]
   | ^

In this case I have no need to create an empty bitfield (despite the Default trait), nor for into_bytes, but there doesn't seem to be a way to silence these warnings or disable these functions. If there's no way to prevent the warnings, perhaps making skip available at the top level (or adding a similar attribute) would be appropriate?

For reference, the struct I'm using is below, based off the binread bitfield example:

#[bitfield(bytes = 1)]
#[derive(BinRead, Default)]
#[br(map = Self::from_bytes)]
struct IdAndFlags {
    #[skip(setters)]
    scsi_id: B2,
    #[skip]
    __: B5,
    #[skip(setters)]
    is_enabled: bool
}

Anyhow, thanks for the nice crate! Its usage in my project is minor, but appreciated nonetheless :)

Robbepop commented 3 years ago

Hi, thanks for the issue report. This should be resolved via https://github.com/Robbepop/modular-bitfield/issues/56. So maybe we can close this issue in favor of the other more detailed one. What do you think?

Anyhow, thanks for the nice crate!

Glad to know! :)

Skirmisher commented 3 years ago

Oops! I searched for some of the warning text and not just "warning" so I didn't see it, sorry.