hawkw / mycelium

🍄 an alleged 'operating system'
https://mycelium.elizas.website
MIT License
548 stars 20 forks source link

feat(bitfield): add `enum_from_bits!` macro #450

Closed hawkw closed 1 year ago

hawkw commented 1 year ago

This branch adds a macro to the mycelium-bitfield crate that allows automatically generating FromBits implementations for enum types that are repr(u{N}). For example, we can now write:

mycelium_bitfield::enum_from_bits! {
    #[derive(Debug, Eq, PartialEq)]
    pub enum MyGeneratedEnum<u8> {
        /// Isn't this cool?
        Wow = 0b1001,
        /// It sure is! :D
        Whoa = 0b0110,
    }
}

This probably should be a derive proc-macro but I'm having so much fun doing macro_rules! crimes in the bitfield crate for whatever reason...

Closes https://github.com/hawkw/mycelium/issues/443