@@ -20,12 +20,8 @@ pub fn traverse_and_callback_mut<'a, Callback>(
20
20
// If the path is empty, we call the callback on each item in the array
21
21
// We iterate because we want the entity objects directly
22
22
for ( index, item) in arr. iter_mut ( ) . enumerate ( ) {
23
- let current_error_path_for_index =
24
- current_error_path. as_ref ( ) . map ( |current_path| {
25
- let mut path = current_path. clone ( ) ;
26
- path. push ( GraphQLErrorPathSegment :: Index ( index) ) ;
27
- path
28
- } ) ;
23
+ let current_error_path_for_index: Option < Vec < GraphQLErrorPathSegment > > =
24
+ extend_error_path_with_index ( & current_error_path, index) ;
29
25
callback ( item, current_error_path_for_index) ;
30
26
}
31
27
} else {
@@ -42,13 +38,7 @@ pub fn traverse_and_callback_mut<'a, Callback>(
42
38
let rest_of_path = & remaining_path[ 1 ..] ;
43
39
for ( index, item) in arr. iter_mut ( ) . enumerate ( ) {
44
40
let current_error_path_for_index =
45
- current_error_path
46
- . as_ref ( )
47
- . map ( |current_error_path_for_index| {
48
- let mut path = current_error_path_for_index. clone ( ) ;
49
- path. push ( GraphQLErrorPathSegment :: Index ( index) ) ;
50
- path
51
- } ) ;
41
+ extend_error_path_with_index ( & current_error_path, index) ;
52
42
traverse_and_callback_mut (
53
43
item,
54
44
rest_of_path,
@@ -106,13 +96,7 @@ pub fn traverse_and_callback_mut<'a, Callback>(
106
96
// If the current data is an array, we need to check each item
107
97
for ( index, item) in arr. iter_mut ( ) . enumerate ( ) {
108
98
let current_error_path_for_index =
109
- current_error_path
110
- . as_ref ( )
111
- . map ( |current_error_path_for_index| {
112
- let mut path = current_error_path_for_index. clone ( ) ;
113
- path. push ( GraphQLErrorPathSegment :: Index ( index) ) ;
114
- path
115
- } ) ;
99
+ extend_error_path_with_index ( & current_error_path, index) ;
116
100
traverse_and_callback_mut (
117
101
item,
118
102
remaining_path,
@@ -126,6 +110,17 @@ pub fn traverse_and_callback_mut<'a, Callback>(
126
110
}
127
111
}
128
112
113
+ fn extend_error_path_with_index (
114
+ current_error_path : & Option < Vec < GraphQLErrorPathSegment > > ,
115
+ index : usize ,
116
+ ) -> Option < Vec < GraphQLErrorPathSegment > > {
117
+ current_error_path. as_ref ( ) . map ( |path| {
118
+ let mut new_path = path. clone ( ) ;
119
+ new_path. push ( GraphQLErrorPathSegment :: Index ( index) ) ;
120
+ new_path
121
+ } )
122
+ }
123
+
129
124
pub fn traverse_and_callback < ' a , E , Callback > (
130
125
current_data : & ' a Value < ' a > ,
131
126
remaining_path : & ' a [ FlattenNodePathSegment ] ,
0 commit comments