Created
June 28, 2025 21:17
-
-
Save freedomtowin/05f8e968ba9ce6a3069f13af7bdcf8bb to your computer and use it in GitHub Desktop.
Example of creating a Gist using Python
This file contains hidden or 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
| // Parse the annotated function | |
| let input_fn: ItemFn = parse_macro_input!(item as ItemFn); | |
| let vis = &input_fn.vis; | |
| let sig = &input_fn.sig; | |
| let body = &input_fn.block; | |
| let ident = &input_fn.sig.ident; | |
| let print_ret = if log_ret { | |
| quote! { | |
| println!("Return value from {}: {:?}", stringify!(#ident), &__ret); | |
| } | |
| } else { | |
| quote! {} | |
| }; | |
| // Splice everything together | |
| quote! { | |
| #vis #sig { | |
| println!("Entering {}", stringify!(#ident)); | |
| #timer_start | |
| // Execute the user’s body, capture the return value. | |
| let __ret = (|| #body)(); | |
| #print_ret | |
| #timer_end | |
| __ret | |
| } | |
| }.into() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment