@@ -16,6 +16,7 @@ use crate::size_hint::{self, SizeHint};
1616use std:: fmt;
1717use std:: iter:: { Enumerate , FromIterator , Fuse , FusedIterator } ;
1818use std:: marker:: PhantomData ;
19+ use std:: ops:: ControlFlow ;
1920
2021/// An iterator adaptor that alternates elements from two iterators until both
2122/// run out.
@@ -93,13 +94,13 @@ where
9394 let res = i. try_fold ( init, |mut acc, x| {
9495 acc = f ( acc, x) ;
9596 match j. next ( ) {
96- Some ( y) => Ok ( f ( acc, y) ) ,
97- None => Err ( acc) ,
97+ Some ( y) => ControlFlow :: Continue ( f ( acc, y) ) ,
98+ None => ControlFlow :: Break ( acc) ,
9899 }
99100 } ) ;
100101 match res {
101- Ok ( acc) => j. fold ( acc, f) ,
102- Err ( acc) => i. fold ( acc, f) ,
102+ ControlFlow :: Continue ( acc) => j. fold ( acc, f) ,
103+ ControlFlow :: Break ( acc) => i. fold ( acc, f) ,
103104 }
104105 }
105106}
@@ -216,14 +217,12 @@ where
216217 let res = i. try_fold ( init, |mut acc, x| {
217218 acc = f ( acc, x) ;
218219 match j. next ( ) {
219- Some ( y) => Ok ( f ( acc, y) ) ,
220- None => Err ( acc) ,
220+ Some ( y) => ControlFlow :: Continue ( f ( acc, y) ) ,
221+ None => ControlFlow :: Break ( acc) ,
221222 }
222223 } ) ;
223- match res {
224- Ok ( val) => val,
225- Err ( val) => val,
226- }
224+ let ( ControlFlow :: Continue ( val) | ControlFlow :: Break ( val) ) = res;
225+ val
227226 }
228227}
229228
@@ -595,14 +594,11 @@ where
595594 F : FnMut ( B , Self :: Item ) -> B ,
596595 {
597596 let res = self . iter . try_fold ( acc, |acc, item| match item {
598- Some ( item) => Ok ( f ( acc, item) ) ,
599- None => Err ( acc) ,
597+ Some ( item) => ControlFlow :: Continue ( f ( acc, item) ) ,
598+ None => ControlFlow :: Break ( acc) ,
600599 } ) ;
601-
602- match res {
603- Ok ( val) => val,
604- Err ( val) => val,
605- }
600+ let ( ControlFlow :: Continue ( val) | ControlFlow :: Break ( val) ) = res;
601+ val
606602 }
607603}
608604
0 commit comments