Check if two field lists have at least one common field by name. This is useful for validating struct compatibility when casting between structs, ensuring that source and target fields have overlapping names.
(
source_fields: &[FieldRef],
target_fields: &[FieldRef],
)
| 490 | /// This is useful for validating struct compatibility when casting between structs, |
| 491 | /// ensuring that source and target fields have overlapping names. |
| 492 | pub fn has_one_of_more_common_fields( |
| 493 | source_fields: &[FieldRef], |
| 494 | target_fields: &[FieldRef], |
| 495 | ) -> bool { |
| 496 | let source_names: HashSet<&str> = source_fields |
| 497 | .iter() |
| 498 | .map(|field| field.name().as_str()) |
| 499 | .collect(); |
| 500 | target_fields |
| 501 | .iter() |
| 502 | .any(|field| source_names.contains(field.name().as_str())) |
| 503 | } |
| 504 | |
| 505 | #[cfg(test)] |
| 506 | mod tests { |