File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
node-graph/node-macro/src Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,39 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
175
175
}
176
176
} ) ;
177
177
178
+ let min_max_args = fields. iter ( ) . map ( |field| match field {
179
+ ParsedField :: Regular {
180
+ pat_ident,
181
+ number_min,
182
+ number_max,
183
+ ty,
184
+ ..
185
+ } => {
186
+ let name = & pat_ident. ident ;
187
+ let mut tokens = quote ! { } ;
188
+ let is_generic = matches ! ( ty, syn:: Type :: Path ( p) if p. path. segments. first( ) . map_or( false , |seg| seg. ident. to_string( ) . chars( ) . next( ) . unwrap( ) . is_uppercase( ) ) ) ;
189
+ if !is_generic {
190
+ if let Some ( min) = number_min {
191
+ tokens = quote ! {
192
+ #tokens
193
+ let #name = if #name < ( #min as #ty) { ( #min as #ty) } else { #name } ;
194
+ } ;
195
+ }
196
+
197
+ if let Some ( max) = number_max {
198
+ tokens = quote ! {
199
+ #tokens
200
+ let #name = if #name > ( #max as #ty) { ( #max as #ty) } else { #name } ;
201
+ } ;
202
+ }
203
+ }
204
+ tokens
205
+ }
206
+ ParsedField :: Node { .. } => {
207
+ quote ! { }
208
+ }
209
+ } ) ;
210
+
178
211
let all_implementation_types = fields. iter ( ) . flat_map ( |field| match field {
179
212
ParsedField :: Regular { implementations, .. } => implementations. into_iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ,
180
213
ParsedField :: Node { implementations, .. } => implementations
@@ -237,6 +270,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
237
270
fn eval( & ' n self , __input: #input_type) -> Self :: Output {
238
271
Box :: pin( async move {
239
272
#( #eval_args) *
273
+ #( #min_max_args) *
240
274
self :: #fn_name( __input #( , #field_names) * ) #await_keyword
241
275
} )
242
276
}
You can’t perform that action at this time.
0 commit comments