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
Implement Debug
for generic Address<V: NetworkValidation>
#1578
Conversation
Previously `Debug` was implemented for both `Address<NetworkChecked>` and `Address<NetworkUnchecked>`, but not for cases when the `NetworkValidation` parameter was generic. This change adds this ability.
Unrelated but it's getting difficult to move around |
I'm not sure if I understand what you're saying correctly, but I think you're experiencing an annoying "poisoning" of downstream generic types which are also forced to do manual impls. I didn't fully realize this when suggesting manual impls. I suspect that just keeping the derive is lesser evil but it depends on how many people and how often will they write generic structs. I suggest we remove it anyway for now and re-add it if many people complain. I will take a look at it myself since I've done something similar in another project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK ebfbe74
Nice PR, thanks!
Oh, you're right! I didn't think of it before. Yes, manual impl on the generic struct will work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK ebfbe74
No objection from me. Though we probably want to discuss, in general, the idea of moving unit tests into their own files, because I think it's a common pattern for 50%+ of source files to be unit tests, which can make it hard to navigate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK ebfbe74
I don't think having tests in a separate file is helpful for navigating files, the tests are at the bottom of the file anyways. I'd prefer not to have a proliferation of FTR I navigate files almost entirely by jumping up and down so file layout is always on my mind. One thing that could be done, is putting important stuff first, as opposed to putting stuff before its used i.e., error types and code can be at the bottom instead of at the top where it is in many files - I've made an effort to start this already with no push back so far :) Also, private methods after they are called. |
Yeah, tests aren't that bad. The Rust Errors could also go to a separate module. |
Well I've exposed my lack of reading |
How about we do this restructure during the feature freeze right before next release? |
I'm not trying to imply we have to do what |
Cool, I willing to give it a try, time will tell if we like it. |
Previously
Debug
was implemented for bothAddress<NetworkChecked>
andAddress<NetworkUnchecked>
, but not for cases when theNetworkValidation
parameter was generic. This change adds this ability. Based on Kixunil's tip.With previous implementation, the
test_address_debug()
resulted in error:The added
Debug
onNetworkChecked
andNetworkUnchecked
are required by compiler.While dealing with derives and impls, I also attempted to turn all the derives on
Address
into manual impls (see Kixunil's suggestion in #1489 (comment)). The motivation behind this was the possibility to remove derives onNetworkChecked
andNetworkUnchecked
, too. However, even with manual impls, all the traits onNetworkChecked
andNetworkUnchecked
were still required by compiler in this sort of situations (see also the rest of the same discussion linked above). I do not fully understand why, perhaps limitation of this way of sealing traits?It can be demonstrated by removing
Debug
derivation onNetworkUnchecked
andNetworkChecked
in this PR and runningtest_address_debug()
.Therefore, if we want to allow users of the library to define types generic in
NetworkValidation
and at the same time derive impls, it seems to me thatNetworkChecked
andNetworkUnchecked
will have to have the same set of impls asAddress
itself.