diff --git a/lib/src/merge.rs b/lib/src/merge.rs index 7151ab142..54d19db13 100644 --- a/lib/src/merge.rs +++ b/lib/src/merge.rs @@ -215,13 +215,18 @@ impl Merge { trivial_merge(&self.removes, &self.adds) } - /// Returns an iterator over the terms. The items will alternate between - /// positive and negative terms, starting with positive (since there's one - /// more of those). + /// Returns an iterator over references to the terms. The items will + /// alternate between positive and negative terms, starting with + /// positive (since there's one more of those). pub fn iter(&self) -> impl Iterator { itertools::interleave(&self.adds, &self.removes) } + /// A version of `Merge::iter()` that iterates over mutable references. + pub fn iter_mut(&mut self) -> impl Iterator { + itertools::interleave(self.adds.iter_mut(), self.removes.iter_mut()) + } + /// Creates a new merge by applying `f` to each remove and add. pub fn map<'a, U>(&'a self, f: impl FnMut(&'a T) -> U) -> Merge { let builder: MergeBuilder = self.iter().map(f).collect(); @@ -268,6 +273,15 @@ impl MergeBuilder { } } +impl IntoIterator for Merge { + type Item = T; + type IntoIter = itertools::Interleave, std::vec::IntoIter>; + + fn into_iter(self) -> Self::IntoIter { + itertools::interleave(self.adds, self.removes) + } +} + impl FromIterator for MergeBuilder { fn from_iter>(iter: I) -> Self { let mut removes = vec![];