@@ -893,53 +893,32 @@ where
893
893
#[ deprecated( note="Use MapOk instead" , since="0.10" ) ]
894
894
pub type MapResults < I , F > = MapOk < I , F > ;
895
895
896
+ #[ derive( Clone ) ]
897
+ pub struct MapSpecialCaseFnOk < F > ( F ) ;
898
+
899
+ impl < F , T , U , E > MapSpecialCaseFn < Result < T , E > > for MapSpecialCaseFnOk < F >
900
+ where
901
+ F : FnMut ( T ) ->U
902
+ {
903
+ type Out = Result < U , E > ;
904
+ fn call ( & mut self , t : Result < T , E > ) -> Self :: Out {
905
+ t. map ( |v| self . 0 ( v) )
906
+ }
907
+ }
908
+
896
909
/// An iterator adapter to apply a transformation within a nested `Result::Ok`.
897
910
///
898
911
/// See [`.map_ok()`](../trait.Itertools.html#method.map_ok) for more information.
899
- #[ derive( Clone ) ]
900
- #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
901
- pub struct MapOk < I , F > {
902
- iter : I ,
903
- f : F
904
- }
912
+ pub type MapOk < I , F > = MapSpecialCase < I , MapSpecialCaseFnOk < F > > ;
905
913
906
914
/// Create a new `MapOk` iterator.
907
915
pub fn map_ok < I , F , T , U , E > ( iter : I , f : F ) -> MapOk < I , F >
908
916
where I : Iterator < Item = Result < T , E > > ,
909
917
F : FnMut ( T ) -> U ,
910
918
{
911
- MapOk {
919
+ MapSpecialCase {
912
920
iter,
913
- f,
914
- }
915
- }
916
-
917
- impl < I , F , T , U , E > Iterator for MapOk < I , F >
918
- where I : Iterator < Item = Result < T , E > > ,
919
- F : FnMut ( T ) -> U ,
920
- {
921
- type Item = Result < U , E > ;
922
-
923
- fn next ( & mut self ) -> Option < Self :: Item > {
924
- self . iter . next ( ) . map ( |v| v. map ( & mut self . f ) )
925
- }
926
-
927
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
928
- self . iter . size_hint ( )
929
- }
930
-
931
- fn fold < Acc , Fold > ( self , init : Acc , mut fold_f : Fold ) -> Acc
932
- where Fold : FnMut ( Acc , Self :: Item ) -> Acc ,
933
- {
934
- let mut f = self . f ;
935
- self . iter . fold ( init, move |acc, v| fold_f ( acc, v. map ( & mut f) ) )
936
- }
937
-
938
- fn collect < C > ( self ) -> C
939
- where C : FromIterator < Self :: Item >
940
- {
941
- let mut f = self . f ;
942
- self . iter . map ( move |v| v. map ( & mut f) ) . collect ( )
921
+ f : MapSpecialCaseFnOk ( f) ,
943
922
}
944
923
}
945
924
0 commit comments