Created
October 23, 2023 04:05
-
-
Save rctrj/4c89c67c8cf172a7e3d91e089339051c to your computer and use it in GitHub Desktop.
display using debug
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
use proc_macro::TokenStream; | |
use quote::quote; | |
use syn::{parse_macro_input, DeriveInput}; | |
#[proc_macro_derive(DisplayUsingDebug)] | |
pub fn derive_display_using_debug(input: TokenStream) -> TokenStream { | |
let ast = parse_macro_input!(input as DeriveInput); | |
let name = ast.ident; | |
TokenStream::from(quote! { | |
impl std::fmt::Display for #name { | |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
write!(f, "{:?}", self) | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment