| Crates.io | thediff |
| lib.rs | thediff |
| version | 0.1.1 |
| created_at | 2025-12-16 07:46:33.402497+00 |
| updated_at | 2025-12-16 08:52:58.406029+00 |
| description | Difference between 2 files in percentages |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1987361 |
| size | 4,875 |
A small Rust crate for calculating how different two files are, expressed as a percentage.
It is useful for file comparison, integrity checks, similarity analysis, or detecting changes
between binary or text files.
Add the crate to your Cargo.toml:
[dependencies]
thediff = "0.1"
use thediff::thediff_strings;
fn main() -> std::io::Result<()> {
let (diff_percent, same_percent) = thediff_strings("0101010", "01010111")?;
println!(
"Different part: {:.2}%, Same part: {:.2}%",
diff_percent, same_percent
);
Ok(())
}
use std::path::Path;
use thediff::thediff_files;
fn main() -> std::io::Result<()> {
let (diff_percent, same_percent) = thediff_files(Path::new("file1.bin"), Path::new("file2.bin"))?;
println!(
"Different part: {:.2}%, Same part: {:.2}%",
diff_percent, same_percent
);
Ok(())
}
use std::path::Path;
use thediff::thediff_files_async;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let (diff_percent, same_percent) =
thediff_files_async(
Path::new("file1.bin"),
Path::new("file2.bin"),
)
.await?;
println!(
"Different part: {:.2}%, Same part: {:.2}%",
diff_percent, same_percent
);
Ok(())
}
The crate compares files utf8 char by char:
Counts how many chars differ
Handles files of different sizes
Extra bytes in the longer file are treated as differences
| File A | File B | Result |
|---|---|---|
| Identical | Identical | 0% |
| 50% bytes differ | Same length | 50% |
| One file empty | Other non-empty | 100% |