diff --git a/src/merge.rs b/src/merge.rs index 371bca9..e3d4876 100644 --- a/src/merge.rs +++ b/src/merge.rs @@ -34,16 +34,19 @@ impl ChunkItem { } } -struct MergeIterator { - left: Vec>, - right: Vec>, +struct MergeIterator<'a, Item> +where + Item: 'a +{ + left: &'a [diff::Result], + right: &'a [diff::Result], li: usize, ri: usize, } -impl MergeIterator { - fn new(left: Vec>, right: Vec>) -> MergeIterator { +impl<'a, Item> MergeIterator<'a, Item> { + fn new(left: &'a [diff::Result], right: &'a [diff::Result]) -> MergeIterator<'a, Item> { MergeIterator { left, right, @@ -53,10 +56,7 @@ impl MergeIterator { } } -impl Iterator for MergeIterator -where - Item: ::std::fmt::Debug + PartialEq -{ +impl<'a, Item> Iterator for MergeIterator<'a, Item> { type Item = ChunkItem; fn next(&mut self) -> Option { @@ -123,7 +123,7 @@ mod test { let oa = diff::chars(o, a); let ob = diff::chars(o, b); - let merge = MergeIterator::new(oa, ob).collect::>(); + let merge = MergeIterator::new(&oa, &ob).collect::>(); assert_eq!(vec![ ChunkItem::stable(Chunk(0..3, 0..3)), ChunkItem::unstable(Chunk(3..6, 3..3)), @@ -142,7 +142,7 @@ mod test { let oa = diff::chars(o, a); let ob = diff::chars(o, b); - let merge = MergeIterator::new(oa, ob).collect::>(); + let merge = MergeIterator::new(&oa, &ob).collect::>(); assert_eq!(vec![ ChunkItem::stable(Chunk(0..3, 0..3)), ChunkItem::unstable(Chunk(3..9, 3..9)), @@ -159,7 +159,7 @@ mod test { let oa = diff::chars(o, a); let ob = diff::chars(o, b); - let merge = MergeIterator::new(oa, ob).collect::>(); + let merge = MergeIterator::new(&oa, &ob).collect::>(); assert_eq!(vec![ ChunkItem::stable(Chunk(0..9, 0..9)), ChunkItem::unstable(Chunk(9..9, 9..12)), @@ -175,7 +175,7 @@ mod test { let oa = diff::chars(o, a); let ob = diff::chars(o, b); - let merge = MergeIterator::new(oa, ob).collect::>(); + let merge = MergeIterator::new(&oa, &ob).collect::>(); assert_eq!(vec![ ChunkItem::stable(Chunk(0..6, 0..6)), ChunkItem::unstable(Chunk(6..9, 6..12)), @@ -191,7 +191,7 @@ mod test { let oa = diff::chars(o, a); let ob = diff::chars(o, b); - let merge = MergeIterator::new(oa, ob).collect::>(); + let merge = MergeIterator::new(&oa, &ob).collect::>(); assert_eq!(vec![ ChunkItem::unstable(Chunk(0..6, 0..6)), ], merge);