项目作者: mitsuhiko

项目描述 :
A high level diffing library for rust based on diffs
高级语言: Rust
项目地址: git://github.com/mitsuhiko/similar.git
创建时间: 2021-01-17T21:19:30Z
项目社区:https://github.com/mitsuhiko/similar

开源协议:Apache License 2.0

下载


Similar: A Diffing Library

Crates.io
License
rustc 1.60.0
Documentation

Similar is a dependency free crate for Rust that implements different diffing
algorithms and high level interfaces for it. It is based on the
pijul implementation of the Patience algorithm and
inherits some ideas from there. It also incorporates the Myers’ diff
algorithm which was largely written by Brandon Williams. This library was
built for the insta snapshot testing library.

  1. use similar::{ChangeTag, TextDiff};
  2. fn main() {
  3. let diff = TextDiff::from_lines(
  4. "Hello World\nThis is the second line.\nThis is the third.",
  5. "Hallo Welt\nThis is the second line.\nThis is life.\nMoar and more",
  6. );
  7. for change in diff.iter_all_changes() {
  8. let sign = match change.tag() {
  9. ChangeTag::Delete => "-",
  10. ChangeTag::Insert => "+",
  11. ChangeTag::Equal => " ",
  12. };
  13. print!("{}{}", sign, change);
  14. }
  15. }

Screenshot

terminal highlighting

What’s in the box?

  • Myers’ diff
  • Patience diff
  • Hunt–McIlroy / Hunt–Szymanski LCS diff
  • Diffing on arbitrary comparable sequences
  • Line, word, character and grapheme level diffing
  • Text and Byte diffing
  • Unified diff generation