summaryrefslogtreecommitdiffstats
path: root/src/edits.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2019-07-20 00:56:33 -0400
committerDan Davison <dandavison7@gmail.com>2019-07-20 18:10:27 -0400
commit003d3c464888f603df63b727adab639b024a6ab3 (patch)
treebc086c1dea1398b257e16064e788a1337a129eee /src/edits.rs
parent94848668f06c9e2c9802e87e2d9bd472914ade98 (diff)
Use generics instead of trait objects; improve declaration
Diffstat (limited to 'src/edits.rs')
-rw-r--r--src/edits.rs22
1 files changed, 13 insertions, 9 deletions
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<Item = char>,
- s1: impl Iterator<Item = char>,
- ) -> usize {
+ fn common_prefix_length<I>(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<Item = char>,
- s1: impl DoubleEndedIterator<Item = char>,
- ) -> (usize, [usize; 2]) {
+ fn suffix_data<I>(s0: I, s1: I) -> (usize, [usize; 2])
+ where
+ I: DoubleEndedIterator<Item = char>,
+ {
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<impl Iterator<Item = char>>) -> usize {
+ fn consume_whitespace<I>(s: &mut Peekable<I>) -> usize
+ where
+ I: Iterator<Item = char>,
+ {
let mut i = 0;
loop {
match s.peek() {