Skip to content

Commit

Permalink
Merge pull request #52 from dewert99/inline
Browse files Browse the repository at this point in the history
Add `#[inline]` attribute to generated methods
  • Loading branch information
dewert99 authored Jan 20, 2024
2 parents 0a73918 + 15c12d3 commit d27e6e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
4 changes: 1 addition & 3 deletions ambassador/src/delegate_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ pub(super) fn delegate_macro<I>(
).unwrap_or_else(|x| x.to_compile_error());
}

let iter = delegate_attributes
.into_iter()
.map(|attr| delegate_single(input, attr));
let iter = delegate_attributes.map(|attr| delegate_single(input, attr));
let res = process_results(iter, |iter| iter.flatten().collect());
res.unwrap_or_else(|x| x.to_compile_error())
}
Expand Down
41 changes: 24 additions & 17 deletions ambassador/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ fn replace_gen_idents(tokens: TokenStream, gen_idents: &[&Ident]) -> TokenStream
}
res
}
fn build_method(
method_sig: &TokenStream,
method_invocation: TokenStream,
extr_attrs: TokenStream,
) -> TokenStream {
quote! {
#[inline]
#extr_attrs
#method_sig {
#method_invocation
}
}
}

fn build_trait_items(
original_item: &TraitItem,
Expand Down Expand Up @@ -264,31 +277,25 @@ fn build_trait_items(
}
};
let method_invocation = build_method_invocation(original_method, &field_ident);
quote! {
#method_sig {
#method_invocation
}
}
build_method(&method_sig, method_invocation, quote!())
},
{
let method_invocation =
build_method_invocation(original_method, &quote!(inner));
quote! {
#method_sig {
match self {
$($variants(inner) => #method_invocation),*
}
let method_invocation = quote! {
match self {
$($variants(inner) => #method_invocation),*
}
}
};
build_method(&method_sig, method_invocation, quote!())
},
{
let method_invocation = build_method_invocation(original_method, &quote!(self));
quote! {
#[deny(unconditional_recursion)]
#method_sig {
#method_invocation
}
}
build_method(
&method_sig,
method_invocation,
quote!(#[deny(unconditional_recursion)]),
)
},
)
}
Expand Down

0 comments on commit d27e6e8

Please sign in to comment.