Convert to a list of Replacement operations. This format is more suitable for generating hunks in the change format.
(&self)
| 475 | /// |
| 476 | /// This format is more suitable for generating hunks in the change format. |
| 477 | pub fn to_replacements(&self) -> Vec<Replacement> { |
| 478 | self.ops |
| 479 | .iter() |
| 480 | .filter_map(|op| match *op { |
| 481 | DiffOp::Equal { .. } => None, |
| 482 | DiffOp::Insert { |
| 483 | old_pos, |
| 484 | new_pos, |
| 485 | len, |
| 486 | } => Some(Replacement::insertion(old_pos, new_pos, len)), |
| 487 | DiffOp::Delete { |
| 488 | old_pos, |
| 489 | new_pos, |
| 490 | len, |
| 491 | } => Some(Replacement::deletion(old_pos, len, new_pos)), |
| 492 | DiffOp::Replace { |
| 493 | old_pos, |
| 494 | old_len, |
| 495 | new_pos, |
| 496 | new_len, |
| 497 | } => Some(Replacement::new(old_pos, old_len, new_pos, new_len)), |
| 498 | }) |
| 499 | .collect() |
| 500 | } |
| 501 | |
| 502 | /// Adjust all operation offsets by adding to the positions. |
| 503 | /// |