2026-05-18 22:30:46 +08:00
|
|
|
use similar::{ChangeTag, 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",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
for change in diff.iter_all_changes() {
|
|
|
|
|
let sign = match change.tag() {
|
2026-05-23 18:45:44 +01:00
|
|
|
| ChangeTag::Delete => "-",
|
|
|
|
|
| ChangeTag::Insert => "+",
|
|
|
|
|
| ChangeTag::Equal => " ",
|
2026-05-18 22:30:46 +08:00
|
|
|
};
|
|
|
|
|
print!("{}{}", sign, change);
|
|
|
|
|
}
|
|
|
|
|
}
|