INNER CODE UNIT · Rust
fmt
MystenLabs/fastcrypto · fastcrypto-derive/src/lib.rs:24
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write!(f, "<elided secret for {}>", stringify!(#name))
}
}
};
gen.into()
}
#[proc_macro_derive(SilentDebug)]
/// Derive the `SilentDebug` trait, which is an implementation of `Debug` that does not print the contents of the struct.
/// This is useful for structs that contain sensitive data, such as private keys.
pub fn silent_debug(source: TokenStream) -> TokenStream {
let ast: DeriveInput = syn::parse(source).expect("Incorrect macro input");
let name = &ast.ident;
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
let gen = quote! {
// In order to ensure that secrets are never leaked, Debug is elided
impl #impl_generics ::std::fmt::Debug for #name #type_generics #where_clause {