From 003d3c464888f603df63b727adab639b024a6ab3 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 20 Jul 2019 00:56:33 -0400 Subject: Use generics instead of trait objects; improve declaration --- src/delta.rs | 9 ++++++--- src/edits.rs | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/delta.rs b/src/delta.rs index 4f3552e7..425f87b7 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -44,12 +44,15 @@ impl State { // | HunkMinus | flush, emit | flush, emit | flush, emit | flush, emit | push | push | // | HunkPlus | flush, emit | flush, emit | flush, emit | flush, emit | flush, push | push | -pub fn delta( - lines: impl Iterator, +pub fn delta( + lines: I, config: &Config, assets: &HighlightingAssets, writer: &mut Write, -) -> std::io::Result<()> { +) -> std::io::Result<()> +where + I: Iterator, +{ // TODO: Painter::new(config) let mut painter = Painter { minus_lines: Vec::new(), diff --git a/src/edits.rs b/src/edits.rs index 18addb08..b3eb43fd 100644 --- a/src/edits.rs +++ b/src/edits.rs @@ -328,10 +328,11 @@ mod string_pair { } } - fn common_prefix_length( - s0: impl Iterator, - s1: impl Iterator, - ) -> usize { + fn common_prefix_length(s0: I, s1: I) -> usize + where + I: Iterator, + I::Item: PartialEq, + { let mut i = 0; for (c0, c1) in s0.zip(s1) { if c0 != c1 { @@ -344,10 +345,10 @@ mod string_pair { } /// Return common suffix length and number of trailing whitespace characters on each string. - fn suffix_data( - s0: impl DoubleEndedIterator, - s1: impl DoubleEndedIterator, - ) -> (usize, [usize; 2]) { + fn suffix_data(s0: I, s1: I) -> (usize, [usize; 2]) + where + I: DoubleEndedIterator, + { let mut s0 = s0.rev().peekable(); let mut s1 = s1.rev().peekable(); let n0 = StringPair::consume_whitespace(&mut s0); @@ -357,7 +358,10 @@ mod string_pair { } /// Consume leading whitespace; return number of characters consumed. - fn consume_whitespace(s: &mut Peekable>) -> usize { + fn consume_whitespace(s: &mut Peekable) -> usize + where + I: Iterator, + { let mut i = 0; loop { match s.peek() { -- cgit v1.2.3