Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make new UInt definition less verbose #51

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

bifurcation
Copy link
Contributor

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 tarcieri merged commit ce1a465 into RustCrypto:master Feb 19, 2024
14 checks passed
@tarcieri
Copy link
Member

Thanks! Definitely an improvement

@bifurcation
Copy link
Contributor Author

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
Copy link
Member

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

@bifurcation
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants