-
Notifications
You must be signed in to change notification settings - Fork 23
FromStr impl for U{256, 512, ...} parses from hex rather than from dec as for u{32, 64, ...} #23
Comments
Currently there is a https://docs.rs/ethereum-types/0.2.3/ethereum_types/struct.U128.html#method.from_dec_str method. But I agree that for Uints we should probably do this by default. Especially given that when you display them it actually prints decimals not hexes). |
i found |
i'd be happy to do the necessary changes. let me know! @debris what are your thoughts on this? |
I have none, just don't break parity too much ;) |
ok ; ) i'll check what this would break to see if it's even feasible to change it. |
I just ran into the exact issue. Did you make any progress on this, @snd? |
println!("{}", "100".parse::<u64>().unwrap());
prints100
as expectedprintln!("{}", "100".parse::<U128>().unwrap());
prints256
becauseFromStr for U128
assumes the string is hex and not dec.this is unexpected and unintuitive! can lead to nasty bugs.
could we change
FromStr for $uint
to parse dec instead of hex to make it more in line with the std integer types?we could add
from_hex_str
offrom_str_radix
(which would be in line with the std integer types: https://doc.rust-lang.org/std/primitive.u64.html#method.from_str_radix) for parsing uints from hex strings.(alternatively we could add a
FromHexStr
trait that looks exactly like theFromStr
trait but interprets input as hex)The text was updated successfully, but these errors were encountered: