@@ -2751,16 +2751,7 @@ where
2751
2751
V : Visitor < ' de > ,
2752
2752
{
2753
2753
for item in self . 0 . iter_mut ( ) {
2754
- // items in the vector are nulled out when used. So we can only use
2755
- // an item if it's still filled in and if the field is one we care
2756
- // about.
2757
- let use_item = match * item {
2758
- None => false ,
2759
- Some ( ( ref c, _) ) => c. as_str ( ) . map_or ( false , |x| variants. contains ( & x) ) ,
2760
- } ;
2761
-
2762
- if use_item {
2763
- let ( key, value) = item. take ( ) . unwrap ( ) ;
2754
+ if let Some ( ( key, value) ) = use_item ( item, variants) {
2764
2755
return visitor. visit_enum ( EnumDeserializer :: new ( key, Some ( value) ) ) ;
2765
2756
}
2766
2757
}
@@ -2912,16 +2903,7 @@ where
2912
2903
T : DeserializeSeed < ' de > ,
2913
2904
{
2914
2905
while let Some ( item) = self . iter . next ( ) {
2915
- // items in the vector are nulled out when used. So we can only use
2916
- // an item if it's still filled in and if the field is one we care
2917
- // about. In case we do not know which fields we want, we take them all.
2918
- let use_item = match * item {
2919
- None => false ,
2920
- Some ( ( ref c, _) ) => c. as_str ( ) . map_or ( false , |key| self . fields . contains ( & key) ) ,
2921
- } ;
2922
-
2923
- if use_item {
2924
- let ( key, content) = item. take ( ) . unwrap ( ) ;
2906
+ if let Some ( ( key, content) ) = use_item ( item, self . fields ) {
2925
2907
self . pending_content = Some ( content) ;
2926
2908
return seed. deserialize ( ContentDeserializer :: new ( key) ) . map ( Some ) ;
2927
2909
}
@@ -2939,3 +2921,26 @@ where
2939
2921
}
2940
2922
}
2941
2923
}
2924
+
2925
+ /// Checks if first element of the specified pair matches one of the key from
2926
+ /// `keys` parameter and if this is true, takes it from the option and returns.
2927
+ /// Otherwise, or if `item` already empty, returns `None`.
2928
+ #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
2929
+ fn use_item < ' de > (
2930
+ item : & mut Option < ( Content < ' de > , Content < ' de > ) > ,
2931
+ keys : & [ & str ] ,
2932
+ ) -> Option < ( Content < ' de > , Content < ' de > ) > {
2933
+ // items in the vector are nulled out when used. So we can only use
2934
+ // an item if it's still filled in and if the field is one we care
2935
+ // about.
2936
+ let use_item = match * item {
2937
+ None => false ,
2938
+ Some ( ( ref c, _) ) => c. as_str ( ) . map_or ( false , |key| keys. contains ( & key) ) ,
2939
+ } ;
2940
+
2941
+ if use_item {
2942
+ item. take ( )
2943
+ } else {
2944
+ None
2945
+ }
2946
+ }
0 commit comments