Skip to content

Commit

Permalink
fix #205 - pub fn function
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Dec 24, 2023
1 parent d4ffb97 commit 9b26be2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 11 additions & 6 deletions macros/src/specta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ pub fn attribute(item: proc_macro::TokenStream) -> syn::Result<proc_macro::Token
let wrapper = format_fn_wrapper(&function.sig.ident);

let visibility = &function.vis;
let maybe_macro_export = match &visibility {
Visibility::Public(_) => quote!(#[macro_export]),
_ => Default::default(),
let (maybe_macro_export, pub_the_trait) = match &visibility {
Visibility::Public(_) => (quote!(#[macro_export]), Default::default()),
_ => (
Default::default(),
quote! {
// allow the macro to be resolved with the same path as the function
#[allow(unused_imports)]
#visibility use #wrapper;
},
),
};

let function_name = &function.sig.ident;
Expand Down Expand Up @@ -63,9 +70,7 @@ pub fn attribute(item: proc_macro::TokenStream) -> syn::Result<proc_macro::Token
(@no_return_type) => { #no_return_type };
}

// allow the macro to be resolved with the same path as the function
#[allow(unused_imports)]
#visibility use #wrapper;
#pub_the_trait
}
.into())
}
3 changes: 3 additions & 0 deletions tests/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ mod test {
#[specta]
fn with_docs() {}

#[specta]
pub fn public_function() {}

// TODO: Finish fixing these

#[test]
Expand Down

0 comments on commit 9b26be2

Please sign in to comment.