Skip to content
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

Send requests via traits and clean up generated code #671

Merged
merged 4 commits into from
Mar 20, 2022
Merged

Conversation

psychon
Copy link
Owner

@psychon psychon commented Mar 20, 2022

Before #664, there was an associated send method on request structs that allowed sending a request based on a struct. #664 removed this, because the struct is now from another crate and cannot get new associated methods.

This PR fixes this by adding new functions to the RequestConnection trait that allow sending a request based on the existing traits for such request structs. For "cleanlyness", this PR also moves the "Reply" associated type around a bit.

Finally, the last remaining pieces of the send() method are merged into their only callers.

Edit: I like the diffstat:

 67 files changed, 3681 insertions(+), 7876 deletions(-)

psychon added 4 commits March 20, 2022 16:30
Commit 105c0fc added three new traits that allow to send a request
simply based on a trait. This commit extends our RequestConnection trait
with functions that use this capability to actually send a request.

For a request which has a reply without FDs, the reply type has to
implement TryParse, but before this commit, the trait only provided
TryParseFd. Thus, this commit moves the "Reply" associated type around
so that only for ReplyFDsRequest it has to implement TryParseFd.

Signed-off-by: Uli Schlachter <[email protected]>
The previous commit added a "Reply" associated type to the
"ReplyRequest" trait. Now, both "Request" and "ReplyRequest" have such
an associated type with a different type. To clean that up, this commit
moves Request::Reply to ReplyRequest::Reply. The code generator is
patched up accordingly.

Additionally, Request::parse_reply() is removed. Instead, the same
functionality is implemented in x11rb-protocol/src/protocol/mod.rs
locally (and not "pub"lically), which is the only place where this was
used before.

Signed-off-by: Uli Schlachter <[email protected]>
Once upon a time, each request struct had an associated method "send()"
that allowed to send the request over an X11 connection.

Commit 8aac79f split the code up so that there is now a
x11rb-protocol and an x11rb crate. The request struct belongs into
x11rb-protocol, but the "send()" method into x11rb. Thus, said commit
replaced the associated functions with just a normal, non-"pub"
function.

This extra, non-public function however only ever had a single caller.
Thus, this commit gets rid of this function and inlines it into its only
caller.

Also: "send()" is no longer necessary. The previous commits added a
possibility to send a request based on the ReplyRequest and
ReplyFDsRequest traits. These new capabilities fully replace the old
"send()" methods.

Signed-off-by: Uli Schlachter <[email protected]>
error: function is never used: `parse_reply_fds`
  --> x11rb-protocol/src/protocol/mod.rs:25:4
   |
25 | fn parse_reply_fds<'a, R: ReplyFDsRequest>(bytes: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Reply, &'a [u8]), ParseError> {
   |    ^^^^^^^^^^^^^^^
   |
   = note: `-D dead-code` implied by `-D warnings`

Signed-off-by: Uli Schlachter <[email protected]>
@mergify mergify bot merged commit aef3b94 into master Mar 20, 2022
@mergify mergify bot deleted the send-via-trait branch March 20, 2022 16:50
@psychon
Copy link
Owner Author

psychon commented Mar 20, 2022

Huh... CI passed for this PR, but after the merge, #669 also affects this. The result is a build failure.

Whoops.

https://github.com/psychon/x11rb/runs/5618475671?check_suite_focus=true

Edit: #672 fixes that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants