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

Implement a macro to allow compile-time parsing of integer literals #18

Open
isaacholt100 opened this issue Feb 25, 2023 · 0 comments
Open

Comments

@isaacholt100
Copy link
Owner

As mentioned in #17, it would be helpful to have a way of initialising integers at compile from a literal. Although the from_str method on the FromStr implementation on bnum integers can be made into a const function (although it would have to be a regular method rather than a trait method currently), this would only allow parsing of decimal literal values. Rust integers can be initialised from a decimal, octal, hexadecimal or binary literal, so it would be good to allow the compile-time parsing of bnum integers from the same bases.

The macro would most likely have to be a proc macro which would mean building a separate crate with this functionality.

The macro syntax could look something like this:

int!(0x64e0453943049583045948340fa3eu256);
int!(-349572394579283457934958374934, I256);

The suffix of uBITS or iBITS would be mandatory, unless an optional second argument was passed, indicating the type of the desired output.

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

No branches or pull requests

1 participant