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

Handle deriving fmt::Debug impl for bitfields instead of std #32

Closed jam1garner closed 3 years ago

jam1garner commented 3 years ago

Implementation for my suggestion from #31.

jam1garner commented 3 years ago

Clippy absolutely calling me out. Ident derefs to str? Ugh I wish I knew that months ago.

Edit: nevermind totally misread the lint.

Robbepop commented 3 years ago

As a test case you could take my example from the issue:

use modular_bitfield::prelude::*;

#[derive(BitfieldSpecifier)]
#[bits = 3]
pub enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }

#[bitfield(specifier = true)]
pub struct Date {
    #[bits = 3]
    weekday: Weekday,
    week: u8,
}

#[bitfield]
pub struct FromTo {
    #[bits = 11]
    from: Date,
    #[bits = 11]
    to: Date,
    distance: B10,
}

The only thing you need in order to make it a real test is to add a fn main() { .. } that asserts the expected debug output.

Robbepop commented 3 years ago

For inspiration on how to do the checks and extractions for attributes on the #[bitfield] struct and re-expansions take a look at: https://github.com/Robbepop/modular-bitfield/blob/robin-implement-repr/impl/src/bitfield.rs#L121

Robbepop commented 3 years ago

I am closing this now since I pulled your commits over to some local branch in order to integrate your derive implementation to the new config architecture. Thanks for the PR and work! Your commits are going to be included in the commit log to honor your work! :)

Robbepop commented 3 years ago

I have created the follow-up PR here: https://github.com/Robbepop/modular-bitfield/pull/39 @jam1garner