Debian Codegraph @

src/trait_handlers/debug/debug_struct.rs

raw symbols SCIP
1 use quoterust-analyzer cargo quote 1.0.47 crate/::{format_identrust-analyzer cargo quote 1.0.47 format/format_ident!, quoterust-analyzer cargo quote 1.0.47 quote!};
2 use synrust-analyzer cargo syn 2.0.119 crate/::{Datarust-analyzer cargo syn 2.0.119 derive/Data#, DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#, Fieldsrust-analyzer cargo syn 2.0.119 data/Fields#, Metarust-analyzer cargo syn 2.0.119 attr/Meta#, Typerust-analyzer cargo syn 2.0.119 ty/Type#};
3
4 use superrust-analyzer cargo educe 0.6.0 trait_handlers/debug/::{
5 modelsrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/::{FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#, FieldNamerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#, TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder#, TypeNamerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeName#},
6 TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler#,
7 };
8 use craterust-analyzer cargo educe 0.6.0 crate/::{commonrust-analyzer cargo educe 0.6.0 common/::ident_indexrust-analyzer cargo educe 0.6.0 common/ident_index/::IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#, Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#};
9
10 pub struct DebugStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/debug/debug_struct/DebugStructHandler#;
11
12 impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for DebugStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/debug/debug_struct/DebugStructHandler# {
13 fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/debug/debug_struct/impl#[DebugStructHandler][TraitHandler]trait_meta_handler().(
14 ast: &DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#,
15 token_stream: &mut proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#,
16 traits: &[Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#],
17 meta: &Metarust-analyzer cargo syn 2.0.119 attr/Meta#,
18 ) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<()> {
19 let is_tuple = {
20 if let Datarust-analyzer cargo syn 2.0.119 derive/Data#::Structrust-analyzer cargo syn 2.0.119 derive/Data#Struct#(data) = &ast.datarust-analyzer cargo syn 2.0.119 derive/DeriveInput#data. {
21 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields., Fieldsrust-analyzer cargo syn 2.0.119 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.119 data/Fields#Unnamed#(_))
22 } else {
23 true
24 }
25 };
26
27 let type_attribute = TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder# {
28 enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder#enable_flag.: true,
29 enable_unsaferust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder#enable_unsafe.: false,
30 enable_namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder#enable_name.: true,
31 enable_named_fieldrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder#enable_named_field.: true,
32 enable_boundrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder#enable_bound.: true,
33 namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder#name.: TypeNamerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeName#::Defaultrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeName#Default#,
34 named_fieldrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttributeBuilder#named_field.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_tuple,
35 }
36 .build_from_debug_metarust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/impl#[TypeAttributeBuilder]build_from_debug_meta().(meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
37
38 let name = type_attribute.namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttribute#name..to_ident_by_identrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/impl#[TypeName]to_ident_by_ident().(&ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.);
39
40 let mut debug_types: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&Typerust-analyzer cargo syn 2.0.119 ty/Type#> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
41
42 let mut builder_token_stream = proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#::newrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream]new().();
43 let mut has_fields = false;
44
45 if type_attribute.named_fieldrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttribute#named_field. {
46 builder_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) = name {
47 quoterust-analyzer cargo quote 1.0.47 quote!!(let mut builder = f.debug_struct(stringify!(#name));)
48 } else {
49 superrust-analyzer cargo educe 0.6.0 trait_handlers/debug/::commonrust-analyzer cargo educe 0.6.0 trait_handlers/debug/common/::create_debug_map_builderrust-analyzer cargo educe 0.6.0 trait_handlers/debug/common/create_debug_map_builder().()
50 });
51
52 if let Datarust-analyzer cargo syn 2.0.119 derive/Data#::Structrust-analyzer cargo syn 2.0.119 derive/Data#Struct#(data) = &ast.datarust-analyzer cargo syn 2.0.119 derive/DeriveInput#data. {
53 for (index, field) in data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields..iterrust-analyzer cargo syn 2.0.119 data/impl#[Fields]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
54 let field_attribute = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder# {
55 enable_namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#enable_name.: true,
56 enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#enable_ignore.: true,
57 enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#enable_method.: true,
58 namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#name.: FieldNamerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#::Defaultrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#Default#,
59 }
60 .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/impl#[FieldAttributeBuilder]build_from_attributes().(&field.attrsrust-analyzer cargo syn 2.0.119 data/Field#attrs., traits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
61
62 if field_attribute.ignorerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttribute#ignore. {
63 continue;
64 }
65
66 let (key, field_name) = match field_attribute.namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttribute#name. {
67 FieldNamerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#::Customrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#Custom#(name) => {
68 (name, IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#::from_ident_with_indexrust-analyzer cargo educe 0.6.0 common/ident_index/impl#[IdentOrIndex]from_ident_with_index().(field.identrust-analyzer cargo syn 2.0.119 data/Field#ident..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(), index))
69 },
70 FieldNamerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#::Defaultrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#Default# => {
71 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = field.identrust-analyzer cargo syn 2.0.119 data/Field#ident..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() {
72 (ident.clonerust-analyzer cargo proc-macro2 1.0.107 impl#[Ident][Clone]clone().(), IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#::fromrust-analyzer cargo educe 0.6.0 common/ident_index/impl#[IdentOrIndex][`From<&Ident>`]from().(ident))
73 } else {
74 (format_identrust-analyzer cargo quote 1.0.47 format/format_ident!!("_{}", index), IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#::fromrust-analyzer cargo educe 0.6.0 common/ident_index/impl#[IdentOrIndex][`From<usize>`]from().(index))
75 }
76 },
77 };
78
79 let ty = &field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty.;
80
81 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(method) = field_attribute.methodrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttribute#method. {
82 builder_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(superrust-analyzer cargo educe 0.6.0 trait_handlers/debug/::commonrust-analyzer cargo educe 0.6.0 trait_handlers/debug/common/::create_format_argrust-analyzer cargo educe 0.6.0 trait_handlers/debug/common/create_format_arg().(
83 ast,
84 ty,
85 &method,
86 quoterust-analyzer cargo quote 1.0.47 quote!!(&self.#field_name),
87 ));
88
89 builder_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(if name.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
90 quoterust-analyzer cargo quote 1.0.47 quote!! (builder.field(stringify!(#key), &arg);)
91 } else {
92 quoterust-analyzer cargo quote 1.0.47 quote!! (builder.entry(&Educe__RawString(stringify!(#key)), &arg);)
93 });
94 } else {
95 debug_types.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ty);
96
97 builder_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(if name.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
98 quoterust-analyzer cargo quote 1.0.47 quote!! (builder.field(stringify!(#key), &self.#field_name);)
99 } else {
100 quoterust-analyzer cargo quote 1.0.47 quote!! (builder.entry(&Educe__RawString(stringify!(#key)), &self.#field_name);)
101 });
102 }
103
104 has_fields = true;
105 }
106 }
107 } else {
108 builder_token_stream
109 .extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(let mut builder = f.debug_tuple(stringify!(#name));));
110
111 if let Datarust-analyzer cargo syn 2.0.119 derive/Data#::Structrust-analyzer cargo syn 2.0.119 derive/Data#Struct#(data) = &ast.datarust-analyzer cargo syn 2.0.119 derive/DeriveInput#data. {
112 for (index, field) in data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields..iterrust-analyzer cargo syn 2.0.119 data/impl#[Fields]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
113 let field_attribute = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder# {
114 enable_namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#enable_name.: false,
115 enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#enable_ignore.: true,
116 enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#enable_method.: true,
117 namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttributeBuilder#name.: FieldNamerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#::Defaultrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldName#Default#,
118 }
119 .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/impl#[FieldAttributeBuilder]build_from_attributes().(&field.attrsrust-analyzer cargo syn 2.0.119 data/Field#attrs., traits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
120
121 if field_attribute.ignorerust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttribute#ignore. {
122 continue;
123 }
124
125 let field_name =
126 IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#::from_ident_with_indexrust-analyzer cargo educe 0.6.0 common/ident_index/impl#[IdentOrIndex]from_ident_with_index().(field.identrust-analyzer cargo syn 2.0.119 data/Field#ident..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(), index);
127
128 let ty = &field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty.;
129
130 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(method) = field_attribute.methodrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/field_attribute/FieldAttribute#method. {
131 builder_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(superrust-analyzer cargo educe 0.6.0 trait_handlers/debug/::commonrust-analyzer cargo educe 0.6.0 trait_handlers/debug/common/::create_format_argrust-analyzer cargo educe 0.6.0 trait_handlers/debug/common/create_format_arg().(
132 ast,
133 ty,
134 &method,
135 quoterust-analyzer cargo quote 1.0.47 quote!!(&self.#field_name),
136 ));
137
138 builder_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! (builder.field(&arg);));
139 } else {
140 debug_types.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ty);
141
142 builder_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! (builder.field(&self.#field_name);));
143 }
144
145 has_fields = true;
146 }
147 }
148 }
149
150 let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.;
151
152 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_fields && name.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
153 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(superrust-analyzer cargo educe 0.6.0 trait_handlers/debug/::panicrust-analyzer cargo educe 0.6.0 trait_handlers/debug/panic/::unit_struct_need_namerust-analyzer cargo educe 0.6.0 trait_handlers/debug/panic/unit_struct_need_name().(ident));
154 }
155
156 let bound = type_attribute.boundrust-analyzer cargo educe 0.6.0 trait_handlers/debug/models/type_attribute/TypeAttribute#bound..into_where_predicates_by_generic_parameters_check_typesrust-analyzer cargo educe 0.6.0 common/bound/impl#[Bound]into_where_predicates_by_generic_parameters_check_types().(
157 &ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..paramsrust-analyzer cargo syn 2.0.119 generics/Generics#params.,
158 &synrust-analyzer cargo syn 2.0.119 crate/::parse2rust-analyzer cargo syn 2.0.119 parse2().(quoterust-analyzer cargo quote 1.0.47 quote!!(::core::fmt::Debug)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
159 &debug_types,
160 &[],
161 );
162
163 let mut generics = ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..clonerust-analyzer cargo syn 2.0.119 gen/clone/impl#[`crate::Generics`][Clone]clone().();
164 let where_clause = generics.make_where_clauserust-analyzer cargo syn 2.0.119 generics/impl#[Generics]make_where_clause().();
165
166 for where_predicate in bound {
167 where_clause.predicatesrust-analyzer cargo syn 2.0.119 generics/WhereClause#predicates..pushrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]push().(where_predicate);
168 }
169
170 let (impl_generics, ty_generics, where_clause) = generics.split_for_implrust-analyzer cargo syn 2.0.119 generics/impl#[Generics]split_for_impl().();
171
172 token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! {
173 impl #impl_generics ::core::fmt::Debug for #ident #ty_generics #where_clause {
174 #[inline]
175 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
176 #builder_token_stream
177
178 builder.finish()
179 }
180 }
181 });
182
183 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
184 }
185 }