RustCrypto / hybrid-array

Hybrid typenum/const generic arrays
Apache License 2.0
9 stars 8 forks source link

Make new UInt definition less verbose #51

Closed bifurcation closed 8 months ago

bifurcation commented 8 months ago

This PR adds a macro that simplifies the definition of new integer values, and uses it for the integers we need to define here. It allows a new UInt type to be defined simply by listing its bits. Unfortunately, because Rust macros only permit recursive matching in one direction, we have to use the little-endian bit order, even though big-endian would be easier to read.

Not a huge change, but it at least allows us to remove the #[rustfmt::skip] line.

tarcieri commented 8 months ago

Thanks! Definitely an improvement

bifurcation commented 8 months ago

BTW, I figured out how to make it big-endian. Requires some trait and associated type magic, but works fine. LMK if this seems worthwhile and I can make a PR.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=363efc88826dac2436cecb2acb8ff21c

tarcieri commented 8 months ago

I'm fine with it being little endian, especially as an internal macro

bifurcation commented 8 months ago

If only there were a way to expand an integer into its bits in the macro syntax!