Skip to main content

text_diff

Function text_diff 

Source
pub fn text_diff(original: &str, modified: &str, path: Option<&str>) -> String
Expand description

Generate a unified diff between two in-memory strings.

Returns an empty string when the contents are identical. The path parameter is used for the --- a/ and +++ b/ diff headers; pass None to use a generic <content> placeholder.

Absolute Unix paths (e.g. after canonicalize()) are normalized so headers do not contain a double slash (--- a//tmp/...): leading / characters are stripped for the header only. Relative paths are unchanged (--- a/src/main.rs).

This is the same diff engine used internally by replace_in_content, replace_text, and other editing operations, exposed as a standalone public API for embedders that need to diff arbitrary strings without going through a full edit operation.