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

Into<uN> and TryFrom<uN> for uN bitfields #77

Closed ryankurte closed 2 years ago

ryankurte commented 2 years ago

hey thanks for making a neat crate!

it seems to me that it would be super useful to have core::convert::TryFrom<uN> and core::convert::Into<uN> implemented for generated bitfield types so one can use these types in a generic manner.

(as an aside, have y'all considered / would y'all be open to extending this with constants a-la bitflags? huge fan of not having to manage structure layouts, but i find myself missing the ability to use simple boolean operations on the objects.)

ryankurte commented 2 years ago

alternately TryFrom<[u8; N]> and Into<[u8; N]> would equally well do the job and be consistent with the existing from_bytes and into_bytes methods.

ryankurte commented 2 years ago

aha! it appears if you add #[repr(uN)] to your #[bitfield] object this happens automatically, though i only discovered this by digging through the proc macros, apparently i can't read the docs