MCPcopy Index your code
hub / github.com/encounter/objdiff / split

Method split

objdiff-core/src/bindings/report.rs:180–240  ·  view source on GitHub ↗

Split the report into multiple reports based on progress categories. Assumes progress categories are in the format `version`, `version.category`. This is a hack for projects that generate all versions in a single report.

(self)

Source from the content-addressed store, hash-verified

178 /// Assumes progress categories are in the format `version`, `version.category`.
179 /// This is a hack for projects that generate all versions in a single report.
180 pub fn split(self) -> Vec<(String, Report)> {
181 let mut reports = Vec::new();
182 // Map units to Option to allow taking ownership
183 let mut units = self.units.into_iter().map(Some).collect::<Vec<_>>();
184 for category in &self.categories {
185 if category.id.contains(".") {
186 // Skip subcategories
187 continue;
188 }
189 fn is_sub_category(id: &str, parent: &str, sep: char) -> bool {
190 id.starts_with(parent) && id.get(parent.len()..).is_some_and(|s| s.starts_with(sep))
191 }
192 let mut sub_categories = self
193 .categories
194 .iter()
195 .filter(|c| is_sub_category(&c.id, &category.id, '.'))
196 .cloned()
197 .collect::<Vec<_>>();
198 // Remove category prefix
199 for sub_category in &mut sub_categories {
200 sub_category.id = sub_category.id[category.id.len() + 1..].to_string();
201 }
202 let mut sub_units = units
203 .iter_mut()
204 .filter_map(|opt| {
205 let unit = opt.as_mut()?;
206 let metadata = unit.metadata.as_ref()?;
207 if metadata.progress_categories.contains(&category.id) {
208 opt.take()
209 } else {
210 None
211 }
212 })
213 .collect::<Vec<_>>();
214 for sub_unit in &mut sub_units {
215 // Remove leading version/ from unit name
216 if let Some(name) =
217 sub_unit.name.strip_prefix(&category.id).and_then(|s| s.strip_prefix('/'))
218 {
219 sub_unit.name = name.to_string();
220 }
221 // Filter progress categories
222 let Some(metadata) = sub_unit.metadata.as_mut() else {
223 continue;
224 };
225 metadata.progress_categories = metadata
226 .progress_categories
227 .iter()
228 .filter(|c| is_sub_category(c, &category.id, '.'))
229 .map(|c| c[category.id.len() + 1..].to_string())
230 .collect();
231 }
232 reports.push((category.id.clone(), Report {
233 measures: category.measures,
234 units: sub_units,
235 version: self.version,
236 categories: sub_categories,
237 }));

Callers 3

fetch_wsl2_distrosFunction · 0.80
drawMethod · 0.80
draw_optionsMethod · 0.80

Calls 2

iter_mutMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected