Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add libp2p-request-response protocol. #1596
Add libp2p-request-response protocol. #1596
Changes from 7 commits
489a8ae
521fe2d
89ea70a
e2a596d
8128079
054811d
0b96c78
eb9c02d
52d47ec
54f56d8
11777d7
a204f73
f964bbc
fa2ee41
9c6e6b4
7bfdff5
2ec63e5
69d13fe
216fca4
9fadb3f
48ad16a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why
Clone
?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.
It is a requirement on inbound events to any
ProtocolsHandler
(due to the general possibility ofNotifyHandler::All
).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.
Where in the type-system is this enforced?
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.
The
ExpandedSwarm
needsClone
onTInEvent
sincenotify_all
needsClone
onTInEvent
. Is that what you were asking for?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.
I noticed that removing
Clone
does not cause compilation to fail. Should the bound not be required by theProtocolsHandler::InEvent
type?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.
Indeed, that is true, the bound here does not seem necessary. Here
InEvent
isstruct RequestProtocol<TCodec>
which has a field of typeTCodec::Request
together with[derive(Clone)]
. So certainlyRequestProtocol
cannot beClone
withoutTCodec::Request
beingClone
(and sure enough the included test with a ping/pong protocol complains firstly about the missingClone
forstruct Ping
due to the requirement forTInEvent: Clone
from theSwarm
). So theTCodec::Request: Clone
bound is probably "implied" by theClone
derive onRequestProtocol
.You mean as an alternative to putting the bound in the
ExpandedSwarm
impl? That would probably work - we have many such cases where theSwarm
orNetwork
is not really useable without certain constraints on some associated types, yet the bounds are placed on methods or impls of theSwarm
orNetwork
, instead of on the associated type. I personally would prefer the bounds to be directly on the associated types in these cases, but it is probably not something for this PR.In any case, I will remove the seemingly unnecessary
Clone
constraint here, thanks for pointing that out.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.
How about using
async-trait
for this trait and writing: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.
I'm personally not a fan of
async-trait
. It hides things from you for a very minimal gain. No strong opinion on this however.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.
Thanks for the suggestion. I wasn't sure how controversial it would be and was even curious if someone would suggest it. While I have no strong preference and it is a relatively small convenience, I do see the appeal in getting syntactic uniformity for async (i.e. future-returning) methods, whether in traits or not. In terms of hiding things I personally don't think it makes the situation worse because the code expands in a very similar way to that of the existing built-in
async fn
s for non-trait methods (subject to the inherent limitations, of course), which one needs to understand in any case. So I haveasync-trait
a try: 9c6e6b4. If there are strong objections, please let me know.