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/edits.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/edits.rs') 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