Crates.io | libxdiff |
lib.rs | libxdiff |
version | 0.2.0 |
source | src |
created_at | 2023-03-29 17:38:09.783435 |
updated_at | 2023-08-02 13:38:49.827066 |
description | Rust bindings for the libxdiff C library |
homepage | https://github.com/bplevin36/libxdiff-rs |
repository | https://github.com/bplevin36/libxdiff-rs |
max_upload_size | |
id | 824249 |
size | 34,257 |
Safe, idiomatic Rust bindings for the libxdiff
C library.
Add this to your Cargo.toml
:
[dependencies]
libxdiff = "0.2"
use core::str::from_utf8;
use libxdiff::MMFile;
let mut f1 = MMFile::from_bytes(b"hello world\n");
let mut f2 = MMFile::from_bytes(b"hello world!\n");
let mut diff_lines = Vec::<String>::new();
f1.diff_raw(&mut f2, |line: &[u8]| {
diff_lines.push(from_utf8(line).unwrap().to_owned());
})
.unwrap();
assert_eq!(
diff_lines,
vec![
"@@ -1,1 +1,1 @@\n",
"-", "hello world\n",
"+", "hello world!\n",
],
);
Upstream libxdiff
is small and has no dependencies, so this crate links it statically.