diff options
Diffstat (limited to 'sylt_macro/src/lib.rs')
| -rw-r--r-- | sylt_macro/src/lib.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/sylt_macro/src/lib.rs b/sylt_macro/src/lib.rs index 1cafde8..9bfef65 100644 --- a/sylt_macro/src/lib.rs +++ b/sylt_macro/src/lib.rs @@ -1,5 +1,7 @@ +use lazy_static::lazy_static; use proc_macro::TokenStream; use quote::quote; +use std::borrow::Cow; use syn::{Expr, Pat, Token, parse::{Parse, ParseStream, Result}, parse_macro_input}; struct ExternBlock { @@ -91,3 +93,22 @@ pub fn extern_function(tokens: TokenStream) -> TokenStream { }; TokenStream::from(tokens) } + +#[proc_macro_attribute] +pub fn extern_link(attr: TokenStream, tokens: TokenStream) -> TokenStream { + let parsed: syn::ItemFn = parse_macro_input!(tokens); + + let name = if attr.is_empty() { + Cow::Borrowed(&parsed.sig.ident) + } else { + let attr: syn::Ident = parse_macro_input!(attr); + Cow::Owned(attr) + }; + + let tokens = quote! { + #parsed + + + }; + TokenStream::from(tokens) +} |
