@@ -41,32 +41,20 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
41
41
let struct_generics: Vec < Ident > = fields. iter ( ) . enumerate ( ) . map ( |( i, _) | format_ident ! ( "Node{}" , i) ) . collect ( ) ;
42
42
let input_ident = & input. pat_ident ;
43
43
44
- let field_idents: Vec < _ > = fields
45
- . iter ( )
46
- . map ( |field| match field {
47
- ParsedField :: Regular { pat_ident, .. } | ParsedField :: Node { pat_ident, .. } => pat_ident,
48
- } )
49
- . collect ( ) ;
44
+ let field_idents: Vec < _ > = fields. iter ( ) . map ( |f| & f. pat_ident ) . collect ( ) ;
50
45
let field_names: Vec < _ > = field_idents. iter ( ) . map ( |pat_ident| & pat_ident. ident ) . collect ( ) ;
51
46
52
47
let input_names: Vec < _ > = fields
53
48
. iter ( )
54
- . map ( |field| match field {
55
- ParsedField :: Regular { name, .. } | ParsedField :: Node { name, .. } => name,
56
- } )
49
+ . map ( |f| & f. name )
57
50
. zip ( field_names. iter ( ) )
58
51
. map ( |zipped| match zipped {
59
52
( Some ( name) , _) => name. value ( ) ,
60
53
( _, name) => name. to_string ( ) . to_case ( Case :: Title ) ,
61
54
} )
62
55
. collect ( ) ;
63
56
64
- let input_descriptions: Vec < _ > = fields
65
- . iter ( )
66
- . map ( |field| match field {
67
- ParsedField :: Regular { description, .. } | ParsedField :: Node { description, .. } => description,
68
- } )
69
- . collect ( ) ;
57
+ let input_descriptions: Vec < _ > = fields. iter ( ) . map ( |f| & f. description ) . collect ( ) ;
70
58
71
59
let struct_fields = field_names. iter ( ) . zip ( struct_generics. iter ( ) ) . map ( |( name, r#gen) | {
72
60
quote ! { pub ( super ) #name: #r#gen }
@@ -84,9 +72,9 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
84
72
85
73
let field_types: Vec < _ > = fields
86
74
. iter ( )
87
- . map ( |field| match field {
88
- ParsedField :: Regular { ty, .. } => ty. clone ( ) ,
89
- ParsedField :: Node { output_type, input_type, .. } => match parsed. is_async {
75
+ . map ( |field| match & field. ty {
76
+ ParsedFieldType :: Regular ( RegularParsedField { ty, .. } ) => ty. clone ( ) ,
77
+ ParsedFieldType :: Node ( NodeParsedField { output_type, input_type, .. } ) => match parsed. is_async {
90
78
true => parse_quote ! ( & ' n impl #graphene_core:: Node <' n, #input_type, Output = impl core:: future:: Future <Output =#output_type>>) ,
91
79
false => parse_quote ! ( & ' n impl #graphene_core:: Node <' n, #input_type, Output = #output_type>) ,
92
80
} ,
@@ -95,24 +83,18 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
95
83
96
84
let widget_override: Vec < _ > = fields
97
85
. iter ( )
98
- . map ( |field| {
99
- let parsed_widget_override = match field {
100
- ParsedField :: Regular { widget_override, .. } => widget_override,
101
- ParsedField :: Node { widget_override, .. } => widget_override,
102
- } ;
103
- match parsed_widget_override {
104
- ParsedWidgetOverride :: None => quote ! ( RegistryWidgetOverride :: None ) ,
105
- ParsedWidgetOverride :: Hidden => quote ! ( RegistryWidgetOverride :: Hidden ) ,
106
- ParsedWidgetOverride :: String ( lit_str) => quote ! ( RegistryWidgetOverride :: String ( #lit_str) ) ,
107
- ParsedWidgetOverride :: Custom ( lit_str) => quote ! ( RegistryWidgetOverride :: Custom ( #lit_str) ) ,
108
- }
86
+ . map ( |field| match & field. widget_override {
87
+ ParsedWidgetOverride :: None => quote ! ( RegistryWidgetOverride :: None ) ,
88
+ ParsedWidgetOverride :: Hidden => quote ! ( RegistryWidgetOverride :: Hidden ) ,
89
+ ParsedWidgetOverride :: String ( lit_str) => quote ! ( RegistryWidgetOverride :: String ( #lit_str) ) ,
90
+ ParsedWidgetOverride :: Custom ( lit_str) => quote ! ( RegistryWidgetOverride :: Custom ( #lit_str) ) ,
109
91
} )
110
92
. collect ( ) ;
111
93
112
94
let value_sources: Vec < _ > = fields
113
95
. iter ( )
114
- . map ( |field| match field {
115
- ParsedField :: Regular { value_source, .. } => match value_source {
96
+ . map ( |field| match & field. ty {
97
+ ParsedFieldType :: Regular ( RegularParsedField { value_source, .. } ) => match value_source {
116
98
ParsedValueSource :: Default ( data) => quote ! ( RegistryValueSource :: Default ( stringify!( #data) ) ) ,
117
99
ParsedValueSource :: Scope ( data) => quote ! ( RegistryValueSource :: Scope ( #data) ) ,
118
100
_ => quote ! ( RegistryValueSource :: None ) ,
@@ -123,8 +105,8 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
123
105
124
106
let default_types: Vec < _ > = fields
125
107
. iter ( )
126
- . map ( |field| match field {
127
- ParsedField :: Regular { implementations, .. } => match implementations. first ( ) {
108
+ . map ( |field| match & field. ty {
109
+ ParsedFieldType :: Regular ( RegularParsedField { implementations, .. } ) => match implementations. first ( ) {
128
110
Some ( ty) => quote ! ( Some ( concrete!( #ty) ) ) ,
129
111
_ => quote ! ( None ) ,
130
112
} ,
@@ -134,8 +116,8 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
134
116
135
117
let number_min_values: Vec < _ > = fields
136
118
. iter ( )
137
- . map ( |field| match field {
138
- ParsedField :: Regular { number_soft_min, number_hard_min, .. } => match ( number_soft_min, number_hard_min) {
119
+ . map ( |field| match & field. ty {
120
+ ParsedFieldType :: Regular ( RegularParsedField { number_soft_min, number_hard_min, .. } ) => match ( number_soft_min, number_hard_min) {
139
121
( Some ( soft_min) , _) => quote ! ( Some ( #soft_min) ) ,
140
122
( None , Some ( hard_min) ) => quote ! ( Some ( #hard_min) ) ,
141
123
( None , None ) => quote ! ( None ) ,
@@ -145,8 +127,8 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
145
127
. collect ( ) ;
146
128
let number_max_values: Vec < _ > = fields
147
129
. iter ( )
148
- . map ( |field| match field {
149
- ParsedField :: Regular { number_soft_max, number_hard_max, .. } => match ( number_soft_max, number_hard_max) {
130
+ . map ( |field| match & field. ty {
131
+ ParsedFieldType :: Regular ( RegularParsedField { number_soft_max, number_hard_max, .. } ) => match ( number_soft_max, number_hard_max) {
150
132
( Some ( soft_max) , _) => quote ! ( Some ( #soft_max) ) ,
151
133
( None , Some ( hard_max) ) => quote ! ( Some ( #hard_max) ) ,
152
134
( None , None ) => quote ! ( None ) ,
@@ -156,77 +138,45 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
156
138
. collect ( ) ;
157
139
let number_mode_range_values: Vec < _ > = fields
158
140
. iter ( )
159
- . map ( |field| match field {
160
- ParsedField :: Regular {
141
+ . map ( |field| match & field. ty {
142
+ ParsedFieldType :: Regular ( RegularParsedField {
161
143
number_mode_range : Some ( number_mode_range) ,
162
144
..
163
- } => quote ! ( Some ( #number_mode_range) ) ,
145
+ } ) => quote ! ( Some ( #number_mode_range) ) ,
164
146
_ => quote ! ( None ) ,
165
147
} )
166
148
. collect ( ) ;
167
149
let number_display_decimal_places: Vec < _ > = fields
168
150
. iter ( )
169
- . map ( |field| match field {
170
- ParsedField :: Regular {
171
- number_display_decimal_places : Some ( decimal_places) ,
172
- ..
173
- }
174
- | ParsedField :: Node {
175
- number_display_decimal_places : Some ( decimal_places) ,
176
- ..
177
- } => {
178
- quote ! ( Some ( #decimal_places) )
179
- }
180
- _ => quote ! ( None ) ,
181
- } )
182
- . collect ( ) ;
183
- let number_step: Vec < _ > = fields
184
- . iter ( )
185
- . map ( |field| match field {
186
- ParsedField :: Regular { number_step : Some ( step) , .. } | ParsedField :: Node { number_step : Some ( step) , .. } => {
187
- quote ! ( Some ( #step) )
188
- }
189
- _ => quote ! ( None ) ,
190
- } )
151
+ . map ( |field| field. number_display_decimal_places . as_ref ( ) . map_or ( quote ! ( None ) , |i| quote ! ( Some ( #i) ) ) )
191
152
. collect ( ) ;
153
+ let number_step: Vec < _ > = fields. iter ( ) . map ( |field| field. number_step . as_ref ( ) . map_or ( quote ! ( None ) , |i| quote ! ( Some ( #i) ) ) ) . collect ( ) ;
192
154
193
- let unit_suffix: Vec < _ > = fields
194
- . iter ( )
195
- . map ( |field| match field {
196
- ParsedField :: Regular { unit : Some ( unit) , .. } | ParsedField :: Node { unit : Some ( unit) , .. } => {
197
- quote ! ( Some ( #unit) )
198
- }
199
- _ => quote ! ( None ) ,
200
- } )
201
- . collect ( ) ;
155
+ let unit_suffix: Vec < _ > = fields. iter ( ) . map ( |field| field. unit . as_ref ( ) . map_or ( quote ! ( None ) , |i| quote ! ( Some ( #i) ) ) ) . collect ( ) ;
202
156
203
157
let exposed: Vec < _ > = fields
204
158
. iter ( )
205
- . map ( |field| match field {
206
- ParsedField :: Regular { exposed, .. } => quote ! ( #exposed) ,
159
+ . map ( |field| match & field. ty {
160
+ ParsedFieldType :: Regular ( RegularParsedField { exposed, .. } ) => quote ! ( #exposed) ,
207
161
_ => quote ! ( true ) ,
208
162
} )
209
163
. collect ( ) ;
210
164
211
- let eval_args = fields. iter ( ) . map ( |field| match field {
212
- ParsedField :: Regular { pat_ident, .. } => {
213
- let name = & pat_ident. ident ;
214
- quote ! { let #name = self . #name. eval( __input. clone( ) ) . await ; }
215
- }
216
- ParsedField :: Node { pat_ident, .. } => {
217
- let name = & pat_ident. ident ;
218
- quote ! { let #name = & self . #name; }
165
+ let eval_args = fields. iter ( ) . map ( |field| {
166
+ let name = & field. pat_ident . ident ;
167
+ match & field. ty {
168
+ ParsedFieldType :: Regular { .. } => {
169
+ quote ! { let #name = self . #name. eval( __input. clone( ) ) . await ; }
170
+ }
171
+ ParsedFieldType :: Node { .. } => {
172
+ quote ! { let #name = & self . #name; }
173
+ }
219
174
}
220
175
} ) ;
221
176
222
- let min_max_args = fields. iter ( ) . map ( |field| match field {
223
- ParsedField :: Regular {
224
- pat_ident,
225
- number_hard_min,
226
- number_hard_max,
227
- ..
228
- } => {
229
- let name = & pat_ident. ident ;
177
+ let min_max_args = fields. iter ( ) . map ( |field| match & field. ty {
178
+ ParsedFieldType :: Regular ( RegularParsedField { number_hard_min, number_hard_max, .. } ) => {
179
+ let name = & field. pat_ident . ident ;
230
180
let mut tokens = quote ! ( ) ;
231
181
if let Some ( min) = number_hard_min {
232
182
tokens. extend ( quote_spanned ! { min. span( ) =>
@@ -241,15 +191,13 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
241
191
}
242
192
tokens
243
193
}
244
- ParsedField :: Node { .. } => {
245
- quote ! ( )
246
- }
194
+ ParsedFieldType :: Node { .. } => quote ! ( ) ,
247
195
} ) ;
248
196
249
- let all_implementation_types = fields. iter ( ) . flat_map ( |field| match field {
250
- ParsedField :: Regular { implementations, .. } => implementations. into_iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ,
251
- ParsedField :: Node { implementations, .. } => implementations
252
- . into_iter ( )
197
+ let all_implementation_types = fields. iter ( ) . flat_map ( |field| match & field. ty {
198
+ ParsedFieldType :: Regular ( RegularParsedField { implementations, .. } ) => implementations. iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ,
199
+ ParsedFieldType :: Node ( NodeParsedField { implementations, .. } ) => implementations
200
+ . iter ( )
253
201
. flat_map ( |implementation| [ implementation. input . clone ( ) , implementation. output . clone ( ) ] )
254
202
. collect ( ) ,
255
203
} ) ;
@@ -260,11 +208,11 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
260
208
let mut clampable_clauses = Vec :: new ( ) ;
261
209
262
210
for ( field, name) in fields. iter ( ) . zip ( struct_generics. iter ( ) ) {
263
- clauses. push ( match ( field, * is_async) {
211
+ clauses. push ( match ( & field. ty , * is_async) {
264
212
(
265
- ParsedField :: Regular {
213
+ ParsedFieldType :: Regular ( RegularParsedField {
266
214
ty, number_hard_min, number_hard_max, ..
267
- } ,
215
+ } ) ,
268
216
_,
269
217
) => {
270
218
let all_lifetime_ty = substitute_lifetimes ( ty. clone ( ) , "all" ) ;
@@ -284,7 +232,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
284
232
#name: #graphene_core:: Node <' n, #input_type, Output = #fut_ident> + #graphene_core:: WasmNotSync
285
233
)
286
234
}
287
- ( ParsedField :: Node { input_type, output_type, .. } , true ) => {
235
+ ( ParsedFieldType :: Node ( NodeParsedField { input_type, output_type, .. } ) , true ) => {
288
236
let id = future_idents. len ( ) ;
289
237
let fut_ident = format_ident ! ( "F{}" , id) ;
290
238
future_idents. push ( fut_ident. clone ( ) ) ;
@@ -294,7 +242,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
294
242
#name: #graphene_core:: Node <' n, #input_type, Output = #fut_ident > + #graphene_core:: WasmNotSync
295
243
)
296
244
}
297
- ( ParsedField :: Node { .. } , false ) => unreachable ! ( ) ,
245
+ ( ParsedFieldType :: Node { .. } , false ) => unreachable ! ( ) ,
298
246
} ) ;
299
247
}
300
248
let where_clause = where_clause. clone ( ) . unwrap_or ( WhereClause {
@@ -454,9 +402,9 @@ fn generate_node_input_references(
454
402
let ( mut modified, mut generic_collector) = FilterUsedGenerics :: new ( fn_generics) ;
455
403
456
404
for ( input_index, ( parsed_input, input_ident) ) in parsed. fields . iter ( ) . zip ( field_idents) . enumerate ( ) {
457
- let mut ty = match parsed_input {
458
- ParsedField :: Regular { ty, .. } => ty,
459
- ParsedField :: Node { output_type, .. } => output_type,
405
+ let mut ty = match & parsed_input. ty {
406
+ ParsedFieldType :: Regular ( RegularParsedField { ty, .. } ) => ty,
407
+ ParsedFieldType :: Node ( NodeParsedField { output_type, .. } ) => output_type,
460
408
}
461
409
. clone ( ) ;
462
410
@@ -540,20 +488,20 @@ fn generate_register_node_impl(parsed: &ParsedNodeFn, field_names: &[&Ident], st
540
488
. fields
541
489
. iter ( )
542
490
. map ( |field| {
543
- match field {
544
- ParsedField :: Regular { implementations, ty, .. } => {
491
+ match & field. ty {
492
+ ParsedFieldType :: Regular ( RegularParsedField { implementations, ty, .. } ) => {
545
493
if !implementations. is_empty ( ) {
546
494
implementations. iter ( ) . map ( |ty| ( & unit, ty) ) . collect ( )
547
495
} else {
548
496
vec ! [ ( & unit, ty) ]
549
497
}
550
498
}
551
- ParsedField :: Node {
499
+ ParsedFieldType :: Node ( NodeParsedField {
552
500
implementations,
553
501
input_type,
554
502
output_type,
555
503
..
556
- } => {
504
+ } ) => {
557
505
if !implementations. is_empty ( ) {
558
506
implementations. iter ( ) . map ( |impl_| ( & impl_. input , & impl_. output ) ) . collect ( )
559
507
} else {
@@ -578,7 +526,7 @@ fn generate_register_node_impl(parsed: &ParsedNodeFn, field_names: &[&Ident], st
578
526
let field_name = field_names[ j] ;
579
527
let ( input_type, output_type) = & types[ i. min ( types. len ( ) - 1 ) ] ;
580
528
581
- let node = matches ! ( parsed. fields[ j] , ParsedField :: Node { .. } ) ;
529
+ let node = matches ! ( parsed. fields[ j] . ty , ParsedFieldType :: Node { .. } ) ;
582
530
583
531
let downcast_node = quote ! (
584
532
let #field_name: DowncastBothNode <#input_type, #output_type> = DowncastBothNode :: new( args[ #j] . clone( ) ) ;
0 commit comments