Debug pin macro (#118)

* debug pin macro

* Added debug pinning macro

* working on windows

* removed remaining box pins
This commit is contained in:
Wyatt Verchere
2023-05-18 10:31:52 -07:00
committed by GitHub
parent 0801d7a145
commit 16407060f0
35 changed files with 1133 additions and 990 deletions

36
theseus_macros/src/lib.rs Normal file
View File

@@ -0,0 +1,36 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn};
#[proc_macro_attribute]
pub fn debug_pin(_attr: TokenStream, item: TokenStream) -> TokenStream {
// Parse the input tokens into a syntax tree
let input = parse_macro_input!(item as ItemFn);
let attrs = &input.attrs;
let vis = &input.vis; // visibility modifier
let sig = &input.sig; // function signature
let body = &input.block;
// Use cfg attribute for conditional compilation
let result = quote! {
#[cfg(debug_assertions)]
#(#attrs) *
#vis #sig {
Box::pin(async move {
#body
}).await
}
#[cfg(not(debug_assertions))]
#(#attrs) *
#vis #sig {
#body
}
};
// Hand the output tokens back to the compiler
TokenStream::from(result)
}