Skip to main content

apply_patch_pure

Function apply_patch_pure 

Source
pub fn apply_patch_pure(
    original: &str,
    patch_text: &str,
) -> Result<String, SkillfileError>
Expand description

Apply a unified diff to original text, returning modified content. Pure implementation — no subprocess, no patch binary required. Only handles patches produced by generate_patch() (unified diff format). Returns an error if the patch does not apply cleanly.

use skillfile_core::patch::{generate_patch, apply_patch_pure};

let original = "line1\nline2\nline3\n";
let modified = "line1\nchanged\nline3\n";
let patch = generate_patch(original, modified, "test.md");
let result = apply_patch_pure(original, &patch).unwrap();
assert_eq!(result, modified);