Skip to content

Instantly share code, notes, and snippets.

@freedomtowin
Created June 28, 2025 21:17
Show Gist options
  • Select an option

  • Save freedomtowin/05f8e968ba9ce6a3069f13af7bdcf8bb to your computer and use it in GitHub Desktop.

Select an option

Save freedomtowin/05f8e968ba9ce6a3069f13af7bdcf8bb to your computer and use it in GitHub Desktop.
Example of creating a Gist using Python
// 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