Skip to content
프로젝트

소개

diffs를 기반으로 하는 Rust용 고수준 diff 라이브러리입니다.

개발 도구

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
+1
in 7 days
+4
in 15 days
+8
in 1 month
+10

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Similar: A Diffing Library

Crates.io License Documentation

Similar is a dependency free crate for Rust that implements different diffing algorithms and high level interfaces for it. It was originally inspired by pijul's diff library but has since changed significantly. This library was built for the insta snapshot testing library.

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() {
            ChangeTag::Delete => "-",
            ChangeTag::Insert => "+",
            ChangeTag::Equal => " ",
        };
        print!("{}{}", sign, change);
    }
}

Screenshot

terminal highlighting

See the example output gallery for commands and sample output from the repository's runnable examples.

What's in the box?

  • Practical heuristic Myers diff and raw Myers diff
  • Patience diff
  • Hunt-style diff
  • Histogram diff
  • Classic LCS table diff
  • Anchored diffs (like git diff --anchored) with any algorithm
  • Git's indent heuristic for readable hunk placement
  • Block-aware edit scripts that detect moved, copied, split and merged lines
  • Diffing on arbitrary comparable sequences
  • Line, word, character and grapheme level diffing
  • Text and Byte diffing
  • Unified diff generation
  • Structured three-way line merging with merge and diff3 conflict output

no_std Support

similar now enables std by default.

For no_std + alloc usage:

[dependencies]
similar = { version = "3", default-features = false }

Backend selection in no_std mode:

  • default (default-features = false): alloc::collections::BTreeMap
  • default-features = false, features = ["hashbrown"]: hashbrown::HashMap

Performance Testing

The repository includes Criterion and allocation benchmarks and a generative performance fuzzer that isolates every diff algorithm, captures stacks on timeouts, and saves reproducible input pairs.

Related Projects

License and Links

관련 프로젝트 살펴보기

불러오는 중…