Skip to content

Commit

Permalink
Portal: When macros generate enums and have zero arguments, dont gene…
Browse files Browse the repository at this point in the history
…rate members for those enums
  • Loading branch information
corigan01 committed Jan 31, 2025
1 parent 091bc24 commit 38131ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
27 changes: 15 additions & 12 deletions crates/portal-macro/src/type_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,11 @@ pub fn generate_ast_portal(portal: &PortalMacroInput) -> TokenStream2 {

quote! {
#portal_vis mod #portal_module_name {
#consts
#defined_types
#enums
#trait_tokens
#consts

/// Client side communication over this portal
pub mod client {
}

/// Server side communication over this portal
pub mod server {
}
#trait_tokens
}
}
}
Expand Down Expand Up @@ -207,8 +200,14 @@ fn endpoints_enum_input(endpoint: &PortalEndpoint, input_enum_ident: &Ident) ->
syn::FnArg::Receiver(receiver) => Ident::new("not_supported_self", receiver.span()),
});

quote! {
#input_enum_ident::#endpoint_enum_front( #(#input_argument_names),* )
if endpoint.input.is_empty() {
quote! {
#input_enum_ident::#endpoint_enum_front
}
} else {
quote! {
#input_enum_ident::#endpoint_enum_front( #(#input_argument_names),* )
}
}
}

Expand Down Expand Up @@ -395,7 +394,11 @@ fn generate_endpoint_enums(
metadata: &PortalMetadata,
) -> TokenStream2 {
let all_input_types = metadata.input_types.iter().map(|(ident, arguments)| {
quote_spanned! {ident.span()=> #ident(#(#arguments),*) }
if arguments.is_empty() {
quote_spanned! {ident.span()=> #ident }
} else {
quote_spanned! {ident.span()=> #ident(#(#arguments),*) }
}
});

let all_output_types = metadata.output_type.iter().map(|(ident, argument)| {
Expand Down
2 changes: 1 addition & 1 deletion meta/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn build(
tokio::join!(build_project(multiboot_mode, emit_asm), DiskImgBaker::new())
};

let artifacts = artifacts.expect("Failed to build artifacts!");
let artifacts = artifacts?;
let mut disk = disk?;

disk.write_bootsector(&artifacts.bootsector).await?;
Expand Down
4 changes: 4 additions & 0 deletions portals/hello-portal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub trait HelloPortal {
#[event = 1]
fn ping_hello_server() -> bool {}

/// Test 2
#[event = 2]
fn get_hello() -> u32 {}

#[event = 3]
fn something_hello() {}
}

0 comments on commit 38131ae

Please sign in to comment.