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

[Feature] Macros to parse Ether and other units from string to U256 #787

Open
cakevm opened this issue Oct 25, 2024 · 1 comment
Open

[Feature] Macros to parse Ether and other units from string to U256 #787

cakevm opened this issue Oct 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@cakevm
Copy link

cakevm commented Oct 25, 2024

Component

primitives

Describe the feature you would like

Often you have fixed values that could already be parsed during compile time. Currently I am initializing those values using lazy_static. My proposal would be to have macros to parse ether, wei, etc. from a string to U256.

Currently you will write:

let val: U256 = parse_units("0.01", "ether").unwrap().get_absolute();

Proposal:

let val: U256 = ether!("0.01");

If the parsing fails it will throw an error during compile time.

Additional context

No response

@cakevm cakevm added the enhancement New feature or request label Oct 25, 2024
@makcandrov
Copy link

if you still need it I open sourced my implementation of these macros: alloy-unit-macros

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

No branches or pull requests

3 participants
@makcandrov @cakevm and others