Skip to main content

apply_diff_to_text_with_mode

Function apply_diff_to_text_with_mode 

Source
pub fn apply_diff_to_text_with_mode(
    input: &str,
    diff: &str,
    mode: ApplyDiffMode,
) -> Result<String, ApplyDiffError>
Expand description

Applies a diff body to input using the requested mode.

Update mode accepts floating sections made of @@ anchors and lines prefixed with , +, or -. Create mode requires every content line to start with +. Existing trailing newlines are preserved by update mode.

§Errors

Returns ApplyDiffError when the body is invalid for mode or cannot be matched against input.

§Example

use agents_tools::{ApplyDiffMode, apply_diff_to_text_with_mode};

let created = apply_diff_to_text_with_mode(
    "",
    "+first\n+second\n+",
    ApplyDiffMode::Create,
)?;
assert_eq!(created, "first\nsecond\n");