educe/trait_handlers/debug/
common.rs1use quote::quote;
2use syn::{DeriveInput, Path, Type};
3
4#[inline]
5pub(crate) fn create_debug_map_builder() -> proc_macro2::TokenStream {
6 quote!(
7 #[allow(non_camel_case_types)] struct Educe__RawString(&'static str);
9
10 impl ::core::fmt::Debug for Educe__RawString {
11 #[inline]
12 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
13 f.write_str(self.0)
14 }
15 }
16
17 let mut builder = f.debug_map();
18 )
19}
20
21#[inline]
22pub(crate) fn create_format_arg(
23 ast: &DeriveInput,
24 field_ty: &Type,
25 format_method: &Path,
26 field_expr: proc_macro2::TokenStream,
27) -> proc_macro2::TokenStream {
28 let ty_ident = &ast.ident;
29
30 let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
36
37 quote!(
38 let arg = {
39 #[allow(non_camel_case_types)] struct Educe__DebugField<V, M>(V, ::core::marker::PhantomData<M>);
41
42 impl #impl_generics ::core::fmt::Debug
43 for Educe__DebugField<&#field_ty, #ty_ident #ty_generics>
44 #where_clause
45 {
46 #[inline]
47 fn fmt(&self, educe__f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
48 #format_method(self.0, educe__f)
49 }
50 }
51
52 Educe__DebugField(#field_expr, ::core::marker::PhantomData::<Self>)
53 };
54 )
55}