Skip to main content

apply

Function apply 

Source
pub fn apply(source: &str, fixes: &[Fix]) -> FixOutcome
Expand description

Apply fixes to a file’s source.

Only safe fixes, only ranges that fit, and only one of any overlapping group.

Fixes are applied last first, so an earlier fix’s offsets stay valid while later ones are still being written. Applying in forward order would require adjusting every subsequent offset by the length delta of every edit before it, which is the same computation with more chances to get it wrong.

Where two fixes overlap, the one starting earlier wins. Arbitrary, but it has to be decided rather than left to whatever order the rules happened to run in — two runs over identical input must produce identical output.