-
Notifications
You must be signed in to change notification settings - Fork 9
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
FromHex
is not a generic hex parsing trait
#74
Comments
Oh, yeah, now I realized my comment about having special error type was bogus. IMO Newtypes can just use |
What should we do for locktimes, scriptnums, sequence numbers and targets? |
Inherent methods. But maybe we could consider |
If all we need to do in order to be generic is to allow 0x prefixes then we should do it. Or is your point that if we support hex-parsing
Agreed that we should have inherent methods so people don't have to import the trait. As for whether the trait should be implemented at all on our newtypes etc., I think it should, even if the trait methods' errors are crappy and non-generic, because it lets people implement serde-like "parse an object in hex from special-purpose stream X or ASCII-computing algorithm Y" functions. |
There are two categories of hex-parseable types: sequences of bytes and integers. The former never have 0x prefix, the latter may have which suggests they should be separate traits.
This is the exact thing I doubt. I don't remember seeing this anywhere and I'm not convinced why we should be the ones responsible for providing this general-purpose functionality. We have enough work with |
In terms of conceptual purity, yes, I see what you're getting at, but from a user POV when I search "hex" in order to parse "hex" I expect to find one thing, not to have to think through more conceptual divisions in the exact task that I'm trying to achieve. We could similarly argue for different methods that parse from bytestreams or that parse from UTF-8 strings, or for different methods that parse bytewise (even lengths) or nibble-wise (odd lengths allowed) etc etc. But we only have the one word "hex" so we ought to use it to cover a reasonably large amount of ground.
serde_json's
Yes we are. Because If we neuter
Yes, but adding support for a 0x prefix is really not a lot of extra work, assuming we support it sufficiently well to handle locktimes and sequence numbers (which in turn will be sufficient for everybody else who simply has a newtyped u64 that they want to parse as hex), and don't go crazy trying to be super generic. |
This part I agree with -- if there's a straightforward path to adding 0x-prefix support later then let's forget about it for now and circle back. |
After thinking about this I'm warming up to it. We could have And we can delay implementing this even until after 1.0, because for our types that we care about (e.g. |
Well, this is Rust, we have
And you want to maintain a fast alternative that everyone wanting it will have to import? I personally would rather not deal with it at least until
Well, that's the thing. I think it makes more sense to be either generic over
That's not what I'm saying. If
Exactly, and I think this is required to not get ourselves into some huge mess. |
I feel you, but we need to at least recover the functionality that For right now I think that means
Ah, yeah, that makes sense. Ok, agreed. |
...and specifically (puttiing this in a separate comment that's easier to reply to/link):
|
That didn't have integer support. So the rest of that comment is moot. |
Ok, cool. Then all I want for now is for us to leave the door open to supporting integers. |
Just throwing this comment in, to complete the move of types to |
@tcharding TBH I don't think that trait should have been public; it looks like it exists mainly to facilitate code reuse for various integer-like types. And the methods in question ought to be intrinsics. And possibly they should be collapsed into just But ok, yes, understood that we need to resolve this one way or another. |
Yes, inherent methods please and if we ever decide to make the trait public we should do it in |
I believe this issue is solved with the PRs above as well as the intention to add integer parsing at some later date. |
The string "a" as a valid hex string but using
FromHex
it cannot be parsed.Also, if the
FromHex
crate is a generic hex parsing trait I would expect to be able to implement it forWrapper(u32)
but the trait is not really suited to that because there is nou32::from_hex
impl andu32::from_str_radix
does not play nicely withFromHex::from_byte_iter
.This is starting to feel like a parse-hex-as-required-by-rust-bitcoin trait (and by extension crate) not a generic hex parsing trait.
To add salt to the wound,
rust-bitcoin
includesFromHexStr
to add parsing of types that can include a prefix, which seems alot like something a generic hex parsing library should handle.The text was updated successfully, but these errors were encountered: