Skip to content

Commit

Permalink
Add explicit len implementations
Browse files Browse the repository at this point in the history
Also removed unecessary type bound on Iterator implementation
of ForwardOrRcCodons.
  • Loading branch information
swooster committed Dec 1, 2022
1 parent 683490e commit 5250dbb
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ where
Self: Iterator,
I: ExactSizeIterator,
{
fn len(&self) -> usize {
self.0.len()
}
}

/// Adapter yielding complementary nucleotide of the contained iterator.
Expand Down Expand Up @@ -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.
Expand All @@ -389,7 +395,7 @@ pub enum ForwardOrRcCodons<I> {
impl<N, I> Iterator for ForwardOrRcCodons<I>
where
N: ToNucleotideLike,
I: DoubleEndedIterator<Item = N> + ExactSizeIterator,
I: DoubleEndedIterator<Item = N>,
{
type Item = <N::NucleotideType as NucleotideLike>::Codon;

Expand Down Expand Up @@ -421,11 +427,18 @@ where
}
}

impl<I> ExactSizeIterator for ForwardOrRcCodons<I>
impl<N, I> ExactSizeIterator for ForwardOrRcCodons<I>
where
Self: Iterator,
I: ExactSizeIterator,
N: ToNucleotideLike,
I: DoubleEndedIterator<Item = N> + ExactSizeIterator,
{
fn len(&self) -> usize {
match self {
Self::Forward(iter) => iter.len(),
Self::Rc(iter) => iter.len(),
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit 5250dbb

Please sign in to comment.