Added example to readme

This commit is contained in:
Armin Ronacher 2021-01-24 02:28:37 +01:00
parent 6a1ba61b3a
commit 058924614a
2 changed files with 15 additions and 1 deletions

View file

@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0" license = "Apache-2.0"
description = "A diff library for Rust" description = "A diff library for Rust"
repository = "https://github.com/mitsuhiko/similar" repository = "https://github.com/mitsuhiko/similar"
keywords = ["diff", "difference", "udiff", "compare", "changes"] keywords = ["diff", "difference", "patience", "compare", "changes"]
readme = "README.md" readme = "README.md"
[dev-dependencies] [dev-dependencies]

View file

@ -12,6 +12,20 @@ It provides both low level implementations of Myer's and the Patience diff
algorithm as well as high level text diffing utilities (such as the ability algorithm as well as high level text diffing utilities (such as the ability
to generate unified diffs). to generate unified diffs).
```rust
use similar::algorithms::Algorithm;
use similar::text::unified_diff;
let unified_diff = unified_diff(
Algorithm::Patience,
old_text,
new_text,
3,
Some(("old.txt", "new.text"))
);
println!("{}", unified_diff);
```
## License and Links ## License and Links
- [Documentation](https://docs.rs/similar/) - [Documentation](https://docs.rs/similar/)