parity-common
parity-common copied to clipboard
[uint] Better constant support
Most ways to construct values seem not to be usable in constants except for zero()
and MAX
. I wonder if it would be possible/desirable to have some way to construct these things in a const context, e.g. with from_big_endian()
? Or by directly providing [u64; N_WORDS]
?
Maybe then this could be made more convenient with macros, e.g. a macro that converts an integer literal to [u64; N_WORDS]
, usable in a const context.
It's possible to create it like
const THE_ANSWER: U256 = U256([42, 0, 0, 0]);
however, I agree a convenient method would be good.
It's possible to create it like
const THE_ANSWER: U256 = U256([42, 0, 0, 0]);
Ahh, I haven't noticed the field is public. Nice.
In https://github.com/CosmWasm/cosmwasm/pull/1071 you find a const implementation of from_be_bytes
/from_le_bytes
for inspiration. Getting something similar in uint directly would be 🎖
FYI https://github.com/gakonst/ethers-rs/issues/2486#issuecomment-1656893389 -- uint v0.9.3 has a few functions that could be const that aren't (e.g. fn one
), whereas uint v0.9.4 has them as const (not sure if it's maximally const).