Skip to content
Myr

Implement ExactSizeIterator for Chain

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent a2caba0 · Browse files · 1 file+21 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−0 removed

  • other:+21 added−0 removed

1 file+21 added−0 removed

modified:src/chain.rs+21 added
24 unmodified lines
25 }26 Buffered { rest } => rest.next(),27 }28 }2930 fn size_hint(&self) -> (usize, Option<usize>) {31 let len = self.len();32 (len, Some(len))33 }34}3536impl DoubleEndedIterator for Chain<'_> {37 fn next_back(&mut self) -> Option<Self::Item> {
12 unmodified lines
50 Buffered { rest } => rest.next_back(),51 }52 }53}5455impl ExactSizeIterator for Chain<'_> {56 fn len(&self) -> usize {57 match &self.state {58 Linked { mut next } => {59 let mut len = 0;60 while let Some(cause) = next {61 next = cause.source();62 len += 1;63 }64 len65 }66 Buffered { rest } => rest.len(),67 }68 }69}