pub fn create_patch<'a>(original: &'a str, modified: &'a str) -> Patch<'a, str>Expand description
Create a patch between two texts.
let original = "\
I am afraid, however, that all I have known - that my story - will be forgotten.
I am afraid for the world that is to come.
Afraid that my plans will fail.
Afraid of a doom worse than the Deepness.
";
let modified = "\
I am afraid, however, that all I have known - that my story - will be forgotten.
I am afraid for the world that is to come.
Afraid that Alendi will fail.
Afraid of a doom brought by the Deepness.
";
let expected = "\
--- original
+++ modified
@@ -1,4 +1,4 @@
I am afraid, however, that all I have known - that my story - will be forgotten.
I am afraid for the world that is to come.
-Afraid that my plans will fail.
-Afraid of a doom worse than the Deepness.
+Afraid that Alendi will fail.
+Afraid of a doom brought by the Deepness.
";
let patch = create_patch(original, modified);
assert_eq!(patch.to_string(), expected);Examples found in repository?
examples/patch_formatter.rs (line 8)
4fn main() {
5 let original = "first line\nlast line";
6 let modified = "first line\nmodified last line";
7
8 let patch = create_patch(original, modified);
9
10 println!("PatchFormatter::Default");
11 println!("{patch}");
12
13 let formatter = PatchFormatter::new().missing_newline_message(false);
14 println!("{formatter:?}");
15 println!("{}", formatter.fmt_patch(&patch));
16
17 let formatter = PatchFormatter::new().with_color();
18 println!("{formatter:?}");
19 println!("{}", formatter.fmt_patch(&patch));
20
21 let formatter = PatchFormatter::new()
22 .with_color()
23 .missing_newline_message(false);
24 println!("{formatter:?}");
25 println!("{}", formatter.fmt_patch(&patch));
26}