From 5250dbb44b2e2c5db6b28970c6debb20159fc0fe Mon Sep 17 00:00:00 2001 From: Steve Wooster Date: Wed, 30 Nov 2022 22:37:27 -0800 Subject: [PATCH] Add explicit len implementations Also removed unecessary type bound on Iterator implementation of ForwardOrRcCodons. --- src/iter.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/iter.rs b/src/iter.rs index b1f42b7..0d9c7c5 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -332,6 +332,9 @@ where Self: Iterator, I: ExactSizeIterator, { + fn len(&self) -> usize { + self.0.len() + } } /// Adapter yielding complementary nucleotide of the contained iterator. @@ -374,6 +377,9 @@ where Self: Iterator, I: ExactSizeIterator, { + fn len(&self) -> usize { + self.0.len() + } } /// Adapter capable of holding either forward codon iterators or reverse complement codon iterators. @@ -389,7 +395,7 @@ pub enum ForwardOrRcCodons { impl Iterator for ForwardOrRcCodons where N: ToNucleotideLike, - I: DoubleEndedIterator + ExactSizeIterator, + I: DoubleEndedIterator, { type Item = ::Codon; @@ -421,11 +427,18 @@ where } } -impl ExactSizeIterator for ForwardOrRcCodons +impl ExactSizeIterator for ForwardOrRcCodons where Self: Iterator, - I: ExactSizeIterator, + N: ToNucleotideLike, + I: DoubleEndedIterator + ExactSizeIterator, { + fn len(&self) -> usize { + match self { + Self::Forward(iter) => iter.len(), + Self::Rc(iter) => iter.len(), + } + } } #[cfg(test)]