alloy-rs / alloy-rs/core

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

未關閉
#787 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Rust
星號
967
分支
274
平均合併
1 天 21 小時
30 天內合併 PR
15

描述

### 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:
```rust
let val: U256 = parse_units("0.01", "ether").unwrap().get_absolute();
```

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

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

### Additional context

_No response_

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。