Updated readme

This commit is contained in:
Armin Ronacher 2021-01-30 23:19:59 +01:00
parent fe73d46799
commit b088bdd9dc

View file

@ -14,19 +14,34 @@ It's intended to be replacement for the popular but unmaintained
[difference] crate. [difference] crate.
```rust ```rust
use similar::algorithms::Algorithm; use similar::text::{ChangeTag, TextDiff};
use similar::text::unified_diff;
let udiff = unified_diff( fn main() {
Algorithm::Patience, let diff = TextDiff::from_lines(
old_text, "Hello World\nThis is the second line.\nThis is the third.",
new_text, "Hallo Welt\nThis is the second line.\nThis is life.\nMoar and more",
3,
Some(("old.txt", "new.text"))
); );
println!("{}", udiff);
for op in diff.ops() {
for change in diff.iter_changes(op) {
let sign = match change.tag() {
ChangeTag::Delete => "-",
ChangeTag::Insert => "+",
ChangeTag::Equal => " ",
};
print!("{}{}", sign, change);
}
}
}
``` ```
## What's in the box?
* Myer's diff
* Patience diff
* Line, word, character and grapheme level diffing
* Unified diff generation
## License and Links ## License and Links
- [Documentation](https://docs.rs/similar/) - [Documentation](https://docs.rs/similar/)