-
Notifications
You must be signed in to change notification settings - Fork 254
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
subxt: Derive std::cmp
traits for subxt payloads and addresses
#1429
Changes from 6 commits
98c9ab7
271e881
db2fac3
329bab9
890c051
eed11c5
e4b5959
3699a90
72ea9be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,11 @@ pub trait RuntimeApiPayload { | |
#[derive(Derivative)] | ||
#[derivative( | ||
Clone(bound = "ArgsData: Clone"), | ||
Debug(bound = "ArgsData: std::fmt::Debug") | ||
Debug(bound = "ArgsData: std::fmt::Debug"), | ||
Eq(bound = "ArgsData: std::cmp::Eq"), | ||
Ord(bound = "ArgsData: std::cmp::Ord"), | ||
PartialEq(bound = "ArgsData: std::cmp::PartialEq"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this generate:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does seem to generate that for the
However, for the others it does match the fields 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What do you mean here? I'd be curious to see the generated output :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is from the address of the constants: impl<ReturnTy> ::std::cmp::PartialEq for Address<ReturnTy> {
fn eq(&self, other: &Self) -> bool {
true && match *self {
Address {
pallet_name: ref __self_0,
constant_name: ref __self_1,
constant_hash: ref __self_2,
_marker: ref __self_3,
} => match *other {
Address {
pallet_name: ref __other_0,
constant_name: ref __other_1,
constant_hash: ref __other_2,
_marker: ref __other_3,
} => {
true && &(*__self_0) == &(*__other_0)
&& &(*__self_1) == &(*__other_1)
&& &(*__self_2) == &(*__other_2)
&& &(*__self_3) == &(*__other_3)
}
},
}
}
} I wanted to say that it generates the expected output. I guess I was a bit confused by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ that's a different type from where this comment is which confused me for a bit; the expanded output for this one should have the bounds like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, yep this is the impl<ArgsData, ReturnTy> ::std::cmp::PartialEq for Payload<ArgsData, ReturnTy>
where
ArgsData: std::cmp::PartialEq,
{
fn eq(&self, other: &Self) -> bool {
true && match *self {
Payload {
trait_name: ref __self_0,
method_name: ref __self_1,
args_data: ref __self_2,
validation_hash: ref __self_3,
_marker: ref __self_4,
} => match *other {
Payload {
trait_name: ref __other_0,
method_name: ref __other_1,
args_data: ref __other_2,
validation_hash: ref __other_3,
_marker: ref __other_4,
} => {
true && &(*__self_0) == &(*__other_0)
&& &(*__self_1) == &(*__other_1)
&& &(*__self_2) == &(*__other_2)
&& &(*__self_3) == &(*__other_3)
&& &(*__self_4) == &(*__other_4)
}
},
}
} |
||
PartialOrd(bound = "ArgsData: std::cmp::PartialOrd") | ||
)] | ||
pub struct Payload<ArgsData, ReturnTy> { | ||
trait_name: Cow<'static, str>, | ||
|
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.
Interesting; it sortof looks like derivative would do this one too (https://docs.rs/derivative/latest/src/derivative/lib.rs.html#61) already, but I guess you ran into an issue using it?
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.
For this avoid the clippy warning, the derivative crate would need to take into account the suggestion from https://rust-lang.github.io/rust-clippy/master/index.html#/non_canonical_partial_ord_impl.
Which is to delegate the
PartialOrd::partial_cmp
implementation, to theOrd::cmp
; I don't think that it does that by the looks of those functions.Probably the clippy rule has been added for implementations without bounds, not sure why it wasn't triggered for our other derives.
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.
Aah ok, basically this issue: mcarton/rust-derivative#115
Probably needs derivative to emit that clippy allow in the relevant place!