-
-
Save rust-play/bbc22f90048223081109b661be05ae9d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lib.rs | |
use proc_macro::TokenStream; | |
use quote::quote; | |
use syn::{parse_macro_input, ItemFn}; | |
#[proc_macro_attribute] | |
pub fn rust_decorator(_attr: TokenStream, input: TokenStream) -> TokenStream { | |
let func = parse_macro_input!(input as ItemFn); | |
let fn_name = &func.sig.ident; | |
quote!{ | |
println!("aaaa"); | |
#fn_name(); | |
}; | |
TokenStream::from(quote!(#func)) | |
} | |
// bin.rs | |
#[rust_decorator] | |
fn task(){ | |
println!("Task is running!!!"); | |
} | |
pub fn main() { | |
task(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment