A high level diffing library for rust based on diffs
1,317
stars
255
commits
Rust
primary language
Aug 29, 2026
updated
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);
}
}

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-features = false): alloc::collections::BTreeMapdefault-features = false, features = ["hashbrown"]: hashbrown::HashMapThe 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.
Rust
99.8%
A high level diffing library for rust based on diffs
1,317
stars
255
commits
Rust
primary language
Aug 29, 2026
updated
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);
}
}

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-features = false): alloc::collections::BTreeMapdefault-features = false, features = ["hashbrown"]: hashbrown::HashMapThe 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.
Rust
99.8%