similar
A dependency-free Rust diffing library with Myers, Patience, Histogram, and LCS algorithms
Repository Health
Technical Analysis
similar is a Rust crate that implements multiple diffing algorithms (Myers, Patience, Hunt-style, Histogram, and classic LCS) behind a single high-level API for comparing arbitrary sequences. It was originally inspired by pijul’s diff implementation and was built to power the insta snapshot testing library, but works equally well as a general-purpose diffing toolkit for text, byte, or custom sequence data.
The crate exposes both a low-level capture_diff/capture_diff_slices interface for diffing any indexable sequence, and a higher-level TextDiff type purpose-built for text: line, word, character, and grapheme-level diffing, unified diff generation, and inline change highlighting. It supports no_std + alloc environments via optional hashbrown/bstr backends, making it usable outside of a standard host environment.
What You Get
- Multiple diff algorithm implementations (Myers, Patience, Hunt-style, Histogram, classic LCS table) selectable via a single
Algorithmenum - A high-level
TextDiffAPI for line, word, character, and grapheme-level text comparison - Unified diff generation (
udiffmodule) compatible with standard patch/diff tooling - Inline change highlighting for rendering fine-grained word/character differences within a changed line
no_std + allocsupport with pluggablehashbrown/bstrbackends for embedded or constrained environments- Generic sequence diffing via
capture_diff/capture_diff_slicesfor any indexable, non-text data
Common Use Cases
- Powering snapshot-testing tools that need to show human-readable diffs between expected and actual output (its original use case in insta)
- Generating unified diffs for CLI tools, patch utilities, or code-review tooling
- Building custom diff/merge views in editors or terminal UIs with word- or character-level highlighting
- Comparing arbitrary structured sequences (not just text) in data-processing or testing pipelines
Under The Hood
Architecture - similar is organized around a low-level algorithms module that implements each diff algorithm (Myers in myers.rs, Patience in patience.rs, Histogram in histogram.rs, Hunt-style in hunt.rs, and classic LCS in lcs.rs) behind a shared capture_diff/capture_diff_slices entry point that operates on any indexable sequence via a CachedLookup abstraction (lookup.rs). Text-specific functionality sits in the text module, where TextDiff (abstraction.rs) wraps the generic algorithms with tokenization for line/word/character/grapheme granularity, and InlineChange (inline.rs) layers word-level highlighting on top of a line-level diff. udiff.rs renders DiffOp sequences produced by the core algorithms into standard unified-diff text. Tech Stack - the crate has zero mandatory dependencies; optional features add unicode-segmentation for grapheme-aware splitting, bstr for byte-string handling, hashbrown/web-time for no_std + alloc targets, and serde for serializing diff ops. Dev-dependencies (insta, criterion) show the crate dogfoods its own downstream consumer (insta) for its test suite and benchmarks. Code Quality - tests are implemented as snapshot tests via insta, with committed .snap files under src/snapshots/ and src/text/snapshots/ covering unified-diff output and text-diff behavior; there is no separate tests/ integration directory, so most correctness checking happens through these snapshots plus the benches/diffs.rs Criterion benchmark. Code is split into small, single-responsibility files per algorithm rather than one large module, aiding readability. API Design - the public surface favors a small number of top-level entry points (TextDiff::from_lines, capture_diff_slices, Algorithm enum) with sensible defaults (Myers algorithm, line-terminated diffing) so a consumer can get a working unified diff in under 10 lines, while lower-level access to DiffOps remains available for callers that need custom rendering.
Used by 8 apps in this directory
AppFlowy
Productivity · Project Management · Collaboration
The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.
Laminar
AI Development · Monitoring
Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.
monty
AI Development · Developer Tools
Run LLM-generated Python code safely inside your agent—no containers, no CPython, no compromise—with sub-microsecond startup.
PeerDB
Data Engineering · Databases
Postgres-native ETL that streams change data capture in real time to Snowflake, BigQuery, ClickHouse, S3, and Kafka — up to 10x faster than general-purpose pipelines, managed through a familiar Postgres SQL interface.
PostHog
Analytics · Monitoring · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
QuestDB
Databases · Analytics
A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.
Vibe Kanban
AI Agents · AI Code Assistants · Project Management
A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.
Zed
Developer Tools · Collaboration · Code Editors
High-performance, multiplayer code editor built in Rust by the creators of Atom and Tree-sitter, with native AI integration and real-time collaboration.