Added serde example

This commit is contained in:
Armin Ronacher 2021-10-03 08:59:45 +02:00
parent 4a81e573c2
commit 11d18ca26b
2 changed files with 19 additions and 0 deletions

View file

@ -63,5 +63,9 @@ required-features = ["text"]
name = "large"
required-features = ["text"]
[[example]]
name = "serde"
required-features = ["text", "serde"]
[profile.release]
debug = true

15
examples/serde.rs Normal file
View file

@ -0,0 +1,15 @@
use similar::TextDiff;
fn main() {
let diff = TextDiff::from_lines(
"Hello World\nThis is the second line.\nThis is the third.",
"Hallo Welt\nThis is the second line.\nThis is life.\nMoar and more",
);
let all_changes = diff
.ops()
.iter()
.flat_map(|op| diff.iter_changes(op))
.collect::<Vec<_>>();
println!("{}", serde_json::to_string_pretty(&all_changes).unwrap());
}