MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / to_replacements

Method to_replacements

atomic-core/src/diff/ops.rs:477–500  ·  view source on GitHub ↗

Convert to a list of Replacement operations. This format is more suitable for generating hunks in the change format.

(&self)

Source from the content-addressed store, hash-verified

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 ///

Callers 1

Calls 3

insertionFunction · 0.50
collectMethod · 0.45
iterMethod · 0.45

Tested by 1