diff --git a/src/text/mod.rs b/src/text/mod.rs index 69c41f4..ef8e525 100644 --- a/src/text/mod.rs +++ b/src/text/mod.rs @@ -437,7 +437,7 @@ impl<'old, 'new, 'bufs, T: DiffableStr + ?Sized + 'old + 'new> TextDiff<'old, 'n pub fn iter_changes<'x, 'slf>( &'slf self, op: &DiffOp, - ) -> impl Iterator> + 'slf + ) -> impl Iterator> + '_ where 'x: 'slf, 'old: 'x, @@ -462,16 +462,13 @@ impl<'old, 'new, 'bufs, T: DiffableStr + ?Sized + 'old + 'new> TextDiff<'old, 'n /// /// This is a shortcut for combining [`TextDiff::ops`] with /// [`TextDiff::iter_changes`]. - pub fn iter_all_changes<'x, 'slf>(&'slf self) -> impl Iterator> + 'slf + pub fn iter_all_changes<'x, 'slf>(&'slf self) -> impl Iterator> + '_ where - 'x: 'slf, + 'x: 'slf + 'old + 'new, 'old: 'x, 'new: 'x, { - // unclear why this needs Box::new here. It seems to infer some really - // odd lifetimes I can't figure out how to work with. - Box::new(self.ops().iter().flat_map(move |op| self.iter_changes(&op))) - as Box> + self.ops().iter().flat_map(move |op| self.iter_changes(&op)) } /// Utility to return a unified diff formatter. @@ -492,14 +489,12 @@ impl<'old, 'new, 'bufs, T: DiffableStr + ?Sized + 'old + 'new> TextDiff<'old, 'n /// /// Requires the `inline` feature. #[cfg(feature = "inline")] - pub fn iter_inline_changes<'x, 'slf>( + pub fn iter_inline_changes<'slf>( &'slf self, op: &DiffOp, - ) -> impl Iterator> + 'slf + ) -> impl Iterator> + '_ where - 'x: 'slf, - 'old: 'x, - 'new: 'x, + 'slf: 'old + 'new, { inline::iter_inline_changes(self, op) } diff --git a/src/udiff.rs b/src/udiff.rs index 5fcc231..9141212 100644 --- a/src/udiff.rs +++ b/src/udiff.rs @@ -176,7 +176,10 @@ impl<'diff, 'old, 'new, 'bufs, T: DiffableStr + ?Sized> UnifiedDiff<'diff, 'old, } /// Write the unified diff as bytes to the output stream. - pub fn to_writer(&self, mut w: W) -> Result<(), io::Error> { + pub fn to_writer(&self, mut w: W) -> Result<(), io::Error> + where + 'diff: 'old + 'new + 'bufs, + { let mut header = self.header.as_ref(); for hunk in self.iter_hunks() { if let Some((old_file, new_file)) = header.take() { @@ -237,18 +240,20 @@ impl<'diff, 'old, 'new, 'bufs, T: DiffableStr + ?Sized> } /// Iterates over all changes in a hunk. - pub fn iter_changes(&self) -> impl Iterator> + '_ { - // unclear why this needs Box::new here. It seems to infer some really - // odd lifetimes I can't figure out how to work with. - Box::new( - self.ops() - .iter() - .flat_map(move |op| self.diff.iter_changes(op)), - ) as Box> + pub fn iter_changes(&self) -> impl Iterator> + '_ + where + 'diff: 'old + 'new + 'bufs, + { + self.ops() + .iter() + .flat_map(move |op| self.diff.iter_changes(op)) } /// Write the hunk as bytes to the output stream. - pub fn to_writer(&self, mut w: W) -> Result<(), io::Error> { + pub fn to_writer(&self, mut w: W) -> Result<(), io::Error> + where + 'diff: 'old + 'new + 'bufs, + { for (idx, change) in self.iter_changes().enumerate() { if idx == 0 { writeln!(w, "{}", self.header())?; @@ -268,6 +273,8 @@ impl<'diff, 'old, 'new, 'bufs, T: DiffableStr + ?Sized> impl<'diff, 'old, 'new, 'bufs, T: DiffableStr + ?Sized> fmt::Display for UnifiedDiffHunk<'diff, 'old, 'new, 'bufs, T> +where + 'diff: 'old + 'new + 'bufs, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for (idx, change) in self.iter_changes().enumerate() { @@ -288,6 +295,8 @@ impl<'diff, 'old, 'new, 'bufs, T: DiffableStr + ?Sized> fmt::Display impl<'diff, 'old, 'new, 'bufs, T: DiffableStr + ?Sized> fmt::Display for UnifiedDiff<'diff, 'old, 'new, 'bufs, T> +where + 'diff: 'old + 'new + 'bufs, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut header = self.header.as_ref();