Helper function to process tuple elements and generate match patterns and assertions. This function handles the common pattern of iterating through elements and: - Creating `_` patterns for wildcards (which need no assertions) - Creating named bindings for other patterns and generating their assertions - Handling field operations like dereferencing # Parameters - `elements`: The tuple elements t
(
elements: &[TupleElement],
prefix: &str,
)
| 324 | /// - `match_patterns`: TokenStreams for use in match arms or destructuring |
| 325 | /// - `assertions`: TokenStreams for the generated assertion code |
| 326 | fn process_tuple_elements( |
| 327 | elements: &[TupleElement], |
| 328 | prefix: &str, |
| 329 | ) -> (Vec<TokenStream>, Vec<TokenStream>) { |
| 330 | let mut match_patterns = Vec::new(); |
| 331 | let mut assertions = Vec::new(); |
| 332 | |
| 333 | for (i, tuple_element) in elements.iter().enumerate() { |
| 334 | match tuple_element { |
| 335 | TupleElement::Positional(pattern) => { |
| 336 | match &**pattern { |
| 337 | Pattern::Wildcard(PatternWildcard { .. }) => { |
| 338 | // Wildcard patterns use `_` in the match pattern |
| 339 | match_patterns.push(quote! { _ }); |
| 340 | } |
| 341 | _ => { |
| 342 | // Non-wildcard patterns need a binding and assertion |
| 343 | let name = quote::format_ident!("{}{}", prefix, i); |
| 344 | match_patterns.push(quote! { #name }); |
| 345 | |
| 346 | // Generate assertion with error collection |
| 347 | let assertion = expand_pattern_assertion("e! { #name }, pattern); |
| 348 | assertions.push(assertion); |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | TupleElement::Indexed(boxed_elem) => { |
| 353 | let pattern = &boxed_elem.pattern; |
| 354 | |
| 355 | match pattern { |
| 356 | Pattern::Wildcard(PatternWildcard { .. }) => { |
| 357 | // Wildcard patterns use `_` in the match pattern |
| 358 | match_patterns.push(quote! { _ }); |
| 359 | } |
| 360 | _ => { |
| 361 | // Non-wildcard patterns need a binding and assertion |
| 362 | let name = quote::format_ident!("{}{}", prefix, i); |
| 363 | match_patterns.push(quote! { #name }); |
| 364 | |
| 365 | // Expand the indexed FieldAssertion starting from the bound element name |
| 366 | let assertion = expand_field_assertion("e! { #name }, boxed_elem); |
| 367 | assertions.push(assertion); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | (match_patterns, assertions) |
| 375 | } |
| 376 | |
| 377 | /// Generate assertion for plain tuples with error collection. |
| 378 | /// Uses match expressions for consistency with enum tuple handling. |
no test coverage detected