Skip to content

Commit

Permalink
Desugar generated async trait to include a Send bound
Browse files Browse the repository at this point in the history
  • Loading branch information
morr0ne committed Feb 20, 2025
1 parent 06c9b54 commit f1a0e0a
Show file tree
Hide file tree
Showing 12 changed files with 23,910 additions and 21,647 deletions.
41 changes: 22 additions & 19 deletions gen/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ pub fn generate_server_code(current: &[Pair], pairs: &[Pair]) -> TokenStream {
const INTERFACE: &'static str = #name;
const VERSION: u32 = #version;

async fn handle_request(
fn handle_request(
&self,
#handler_args
message: &mut crate::wire::Message,
) -> crate::server::Result<()> {
#[allow(clippy::match_single_binding)]
match message.opcode {
#(#dispatchers),*
_ => Err(crate::server::error::Error::UnknownOpcode),
) -> impl std::future::Future<Output = crate::server::Result<()>> + Send {
async move {
#[allow(clippy::match_single_binding)]
match message.opcode {
#(#dispatchers),*
_ => Err(crate::server::error::Error::UnknownOpcode),
}
}
}

Expand All @@ -90,7 +92,6 @@ pub fn generate_server_code(current: &[Pair], pairs: &[Pair]) -> TokenStream {
}

quote! {
#![allow(async_fn_in_trait)]
#(#modules)*
}
}
Expand Down Expand Up @@ -202,7 +203,7 @@ fn write_requests(pairs: &[Pair], pair: &Pair, interface: &Interface) -> Vec<Tok

requests.push(quote! {
#(#docs)*
async fn #name(#(#args),*) -> crate::server::Result<()>;
fn #name(#(#args),*) -> impl std::future::Future<Output = crate::server::Result<()>> + Send;
});
}

Expand Down Expand Up @@ -315,17 +316,19 @@ fn write_events(pairs: &[Pair], pair: &Pair, interface: &Interface) -> Vec<Token

events.push(quote! {
#(#docs)*
async fn #name(#(#args),*) -> crate::server::Result<()> {
tracing::debug!(#tracing_inner, sender_id, #(#tracing_args),*);

let (payload,fds) = crate::wire::PayloadBuilder::new()
#(#build_args)*
.build();

client
.send_message(crate::wire::Message::new(sender_id, #opcode, payload, fds))
.await
.map_err(crate::server::error::Error::IoError)
fn #name(#(#args),*) -> impl std::future::Future<Output = crate::server::Result<()>> + Send {
async move {
tracing::debug!(#tracing_inner, sender_id, #(#tracing_args),*);

let (payload,fds) = crate::wire::PayloadBuilder::new()
#(#build_args)*
.build();

client
.send_message(crate::wire::Message::new(sender_id, #opcode, payload, fds))
.await
.map_err(crate::server::error::Error::IoError)
}
}
});
}
Expand Down
3,547 changes: 1,866 additions & 1,681 deletions src/server/protocol/core.rs

Large diffs are not rendered by default.

2,607 changes: 1,365 additions & 1,242 deletions src/server/protocol/cosmic.rs

Large diffs are not rendered by default.

375 changes: 189 additions & 186 deletions src/server/protocol/frog.rs

Large diffs are not rendered by default.

920 changes: 480 additions & 440 deletions src/server/protocol/hyprland.rs

Large diffs are not rendered by default.

Loading

0 comments on commit f1a0e0a

Please sign in to comment.