(&mut self, init: Acc, mut f: F) -> R
+ #[inline]
+ fn rfind(&mut self, mut predicate: P) -> Option
+ where
+ P: FnMut(&Self::Item) -> bool,
+ {
+ match fuse!(self.b.rfind(&mut predicate)) {
+ None => fuse!(self.a.rfind(predicate)),
+ item => item,
+ }
+ }
+
+ fn try_rfold(&mut self, mut acc: Acc, mut f: F) -> R
where
Self: Sized,
F: FnMut(Acc, Self::Item) -> R,
R: Try,
{
- let mut accum = init;
- match self.state {
- ChainState::Both | ChainState::Back => {
- accum = self.b.try_rfold(accum, &mut f)?;
- if let ChainState::Both = self.state {
- self.state = ChainState::Front;
- }
- }
- _ => {}
+ if let Some(ref mut b) = self.b {
+ acc = b.try_rfold(acc, &mut f)?;
+ self.b = None;
}
- if let ChainState::Front = self.state {
- accum = self.a.try_rfold(accum, &mut f)?;
+ if let Some(ref mut a) = self.a {
+ acc = a.try_rfold(acc, f)?;
+ self.a = None;
}
- Try::from_ok(accum)
+ Try::from_ok(acc)
}
- fn rfold(self, init: Acc, mut f: F) -> Acc
+ fn rfold(self, mut acc: Acc, mut f: F) -> Acc
where
F: FnMut(Acc, Self::Item) -> Acc,
{
- let mut accum = init;
- match self.state {
- ChainState::Both | ChainState::Back => {
- accum = self.b.rfold(accum, &mut f);
- }
- _ => {}
+ if let Some(b) = self.b {
+ acc = b.rfold(acc, &mut f);
}
- match self.state {
- ChainState::Both | ChainState::Front => {
- accum = self.a.rfold(accum, &mut f);
- }
- _ => {}
+ if let Some(a) = self.a {
+ acc = a.rfold(acc, f);
}
- accum
+ acc
}
}
// Note: *both* must be fused to handle double-ended iterators.
+// Now that we "fuse" both sides, we *could* implement this unconditionally,
+// but we should be cautious about committing to that in the public API.
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for Chain
where