项目
在 GitHub 查看
mitsuhiko/similar
关于
一个基于 diffs 的 Rust 高级差异比较库。
开发工具实测星标增长
- 24小时
- +1
- 7天
- +4
- 15天
- +8
- 1个月
- +10
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Similar: A Diffing Library
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

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
- insta snapshot testing library
- similar-asserts assertion library
- similar-rs Python bindings
License and Links
探索相关项目
加载中…