The iter_changes method in DiffOp requires old and new to be Index<usize, Output = &'x T>, which makes it unusable in many situations; the doc's example won't compile if I change the type of vector from Vec<&str> to Vec<usize>:
use similar::{ChangeTag, Algorithm};
use similar::capture_diff_slices;
let old = vec![1, 2, 3]; // changed from let old = vec!["foo", "bar", "baz"];
let new = vec![1, 2, 4]; // changed from let new = vec!["foo", "bar", "blah"];
let ops = capture_diff_slices(Algorithm::Myers, &old, &new);
let changes: Vec<_> = ops
.iter()
.flat_map(|x| x.iter_changes(&old, &new))
.map(|x| (x.tag(), x.value()))
.collect();
assert_eq!(changes, vec![
(ChangeTag::Equal, "foo"),
(ChangeTag::Equal, "bar"),
(ChangeTag::Delete, "baz"),
(ChangeTag::Insert, "blah"),
]);
I know the Rust compiler make this almost impossible, but is there any workaround for this?
First of all, thank you for this crate.
The
iter_changes
method inDiffOp
requiresold
andnew
to beIndex<usize, Output = &'x T>
, which makes it unusable in many situations; the doc's example won't compile if I change the type of vector fromVec<&str>
toVec<usize>
:I know the Rust compiler make this almost impossible, but is there any workaround for this?