@@ -806,34 +806,51 @@ impl_tuple_combination!(Tuple2Combination Tuple1Combination ; A, A, A ; a);
806
806
impl_tuple_combination ! ( Tuple3Combination Tuple2Combination ; A , A , A , A ; a b) ;
807
807
impl_tuple_combination ! ( Tuple4Combination Tuple3Combination ; A , A , A , A , A ; a b c) ;
808
808
809
- /// An iterator adapter to apply `Into` conversion to each element.
810
- ///
811
- /// See [`.map_into()`](../trait.Itertools.html#method.map_into) for more information.
809
+ pub trait MapSpecialCaseFn < T > {
810
+ type Out ;
811
+ fn call ( & mut self , t : T ) -> Self :: Out ;
812
+ }
813
+
814
+ #[ derive( Clone ) ]
815
+ pub struct MapSpecialCaseFnInto < U > ( PhantomData < U > ) ;
816
+
817
+ impl < T : Into < U > , U > MapSpecialCaseFn < T > for MapSpecialCaseFnInto < U > {
818
+ type Out = U ;
819
+ fn call ( & mut self , t : T ) -> Self :: Out {
820
+ t. into ( )
821
+ }
822
+ }
823
+
812
824
#[ derive( Clone ) ]
813
825
#[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
814
- pub struct MapInto < I , R > {
826
+ pub struct MapSpecialCase < I , F > {
815
827
iter : I ,
816
- _res : PhantomData < R > ,
828
+ f : F ,
817
829
}
818
830
831
+ /// An iterator adapter to apply `Into` conversion to each element.
832
+ ///
833
+ /// See [`.map_into()`](../trait.Itertools.html#method.map_into) for more information.
834
+ pub type MapInto < I , R > = MapSpecialCase < I , MapSpecialCaseFnInto < R > > ;
835
+
819
836
/// Create a new [`MapInto`](struct.MapInto.html) iterator.
820
837
pub fn map_into < I , R > ( iter : I ) -> MapInto < I , R > {
821
- MapInto {
838
+ MapSpecialCase {
822
839
iter,
823
- _res : PhantomData ,
840
+ f : MapSpecialCaseFnInto ( PhantomData ) ,
824
841
}
825
842
}
826
843
827
- impl < I , R > Iterator for MapInto < I , R >
844
+ impl < I , R > Iterator for MapSpecialCase < I , R >
828
845
where I : Iterator ,
829
- I :: Item : Into < R > ,
846
+ R : MapSpecialCaseFn < I :: Item > ,
830
847
{
831
- type Item = R ;
848
+ type Item = R :: Out ;
832
849
833
850
fn next ( & mut self ) -> Option < Self :: Item > {
834
851
self . iter
835
852
. next ( )
836
- . map ( |i| i . into ( ) )
853
+ . map ( |i| self . f . call ( i ) )
837
854
}
838
855
839
856
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -843,25 +860,26 @@ impl<I, R> Iterator for MapInto<I, R>
843
860
fn fold < Acc , Fold > ( self , init : Acc , mut fold_f : Fold ) -> Acc
844
861
where Fold : FnMut ( Acc , Self :: Item ) -> Acc ,
845
862
{
846
- self . iter . fold ( init, move |acc, v| fold_f ( acc, v. into ( ) ) )
863
+ let mut f = self . f ;
864
+ self . iter . fold ( init, move |acc, v| fold_f ( acc, f. call ( v) ) )
847
865
}
848
866
}
849
867
850
- impl < I , R > DoubleEndedIterator for MapInto < I , R >
868
+ impl < I , R > DoubleEndedIterator for MapSpecialCase < I , R >
851
869
where I : DoubleEndedIterator ,
852
- I :: Item : Into < R > ,
870
+ R : MapSpecialCaseFn < I :: Item > ,
853
871
{
854
872
fn next_back ( & mut self ) -> Option < Self :: Item > {
855
873
self . iter
856
874
. next_back ( )
857
- . map ( |i| i . into ( ) )
875
+ . map ( |i| self . f . call ( i ) )
858
876
}
859
877
}
860
878
861
- impl < I , R > ExactSizeIterator for MapInto < I , R >
879
+ impl < I , R > ExactSizeIterator for MapSpecialCase < I , R >
862
880
where
863
881
I : ExactSizeIterator ,
864
- I :: Item : Into < R > ,
882
+ R : MapSpecialCaseFn < I :: Item > ,
865
883
{ }
866
884
867
885
/// See [`MapOk`](struct.MapOk.html).
0 commit comments