internal: remove unneeded boxes (#12)
This commit is contained in:
parent
0341515380
commit
6fac8af4d0
2 changed files with 26 additions and 22 deletions
|
|
@ -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<Item = Change<'x, T>> + 'slf
|
||||
) -> impl Iterator<Item = Change<'x, T>> + '_
|
||||
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<Item = Change<'x, T>> + 'slf
|
||||
pub fn iter_all_changes<'x, 'slf>(&'slf self) -> impl Iterator<Item = Change<'x, T>> + '_
|
||||
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<dyn Iterator<Item = _>>
|
||||
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<Item = InlineChange<'x, T>> + 'slf
|
||||
) -> impl Iterator<Item = InlineChange<'slf, T>> + '_
|
||||
where
|
||||
'x: 'slf,
|
||||
'old: 'x,
|
||||
'new: 'x,
|
||||
'slf: 'old + 'new,
|
||||
{
|
||||
inline::iter_inline_changes(self, op)
|
||||
}
|
||||
|
|
|
|||
29
src/udiff.rs
29
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<W: io::Write>(&self, mut w: W) -> Result<(), io::Error> {
|
||||
pub fn to_writer<W: io::Write>(&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<Item = Change<'_, T>> + '_ {
|
||||
// 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<dyn Iterator<Item = _>>
|
||||
pub fn iter_changes(&self) -> impl Iterator<Item = Change<'diff, T>> + '_
|
||||
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<W: io::Write>(&self, mut w: W) -> Result<(), io::Error> {
|
||||
pub fn to_writer<W: io::Write>(&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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue