Find matching sections between each object.
(left: Option<&Object>, right: Option<&Object>)
| 761 | |
| 762 | /// Find matching sections between each object. |
| 763 | fn matching_sections(left: Option<&Object>, right: Option<&Object>) -> Result<Vec<SectionMatch>> { |
| 764 | let mut matches = Vec::with_capacity( |
| 765 | left.as_ref() |
| 766 | .map_or(0, |o| o.sections.len()) |
| 767 | .max(right.as_ref().map_or(0, |o| o.sections.len())), |
| 768 | ); |
| 769 | if let Some(left) = left { |
| 770 | for (section_idx, section) in left.sections.iter().enumerate() { |
| 771 | if section.kind == SectionKind::Unknown { |
| 772 | continue; |
| 773 | } |
| 774 | matches.push(SectionMatch { |
| 775 | left: Some(section_idx), |
| 776 | right: find_section(right, §ion.name, section.kind, &matches), |
| 777 | section_kind: section.kind, |
| 778 | }); |
| 779 | } |
| 780 | } |
| 781 | if let Some(right) = right { |
| 782 | for (section_idx, section) in right.sections.iter().enumerate() { |
| 783 | if section.kind == SectionKind::Unknown { |
| 784 | continue; |
| 785 | } |
| 786 | if matches.iter().any(|m| m.right == Some(section_idx)) { |
| 787 | continue; |
| 788 | } |
| 789 | matches.push(SectionMatch { |
| 790 | left: None, |
| 791 | right: Some(section_idx), |
| 792 | section_kind: section.kind, |
| 793 | }); |
| 794 | } |
| 795 | } |
| 796 | Ok(matches) |
| 797 | } |
| 798 | |
| 799 | fn find_section( |
| 800 | obj: Option<&Object>, |
no test coverage detected