@@ -41,16 +41,12 @@ pub fn register_std_array_function_signatures(map: &mut HashMap<&'static str, Si
41
41
"array_append" ,
42
42
Signature {
43
43
parameters : vec ! [
44
- Box :: new( ArrayType {
45
- base: Box :: new( AnyType ) ,
46
- } ) ,
44
+ Box :: new( ArrayType :: new( Box :: new( AnyType ) ) ) ,
47
45
Box :: new( DynamicType {
48
46
function: |elements| array_element_type( first_element_type( elements) ) ,
49
47
} ) ,
50
48
] ,
51
- return_type : Box :: new ( DynamicType {
52
- function : first_element_type,
53
- } ) ,
49
+ return_type : Box :: new ( DynamicType :: new ( first_element_type) ) ,
54
50
} ,
55
51
) ;
56
52
map. insert (
@@ -62,41 +58,29 @@ pub fn register_std_array_function_signatures(map: &mut HashMap<&'static str, Si
62
58
function: |elements| array_of_type( first_element_type( elements) ) ,
63
59
} ) ,
64
60
] ,
65
- return_type : Box :: new ( DynamicType {
66
- function : second_element_type,
67
- } ) ,
61
+ return_type : Box :: new ( DynamicType :: new ( second_element_type) ) ,
68
62
} ,
69
63
) ;
70
64
map. insert (
71
65
"array_remove" ,
72
66
Signature {
73
67
parameters : vec ! [
74
- Box :: new( ArrayType {
75
- base: Box :: new( AnyType ) ,
76
- } ) ,
68
+ Box :: new( ArrayType :: new( Box :: new( AnyType ) ) ) ,
77
69
Box :: new( DynamicType {
78
70
function: |elements| array_element_type( first_element_type( elements) ) ,
79
71
} ) ,
80
72
] ,
81
- return_type : Box :: new ( DynamicType {
82
- function : first_element_type,
83
- } ) ,
73
+ return_type : Box :: new ( DynamicType :: new ( first_element_type) ) ,
84
74
} ,
85
75
) ;
86
76
map. insert (
87
77
"array_cat" ,
88
78
Signature {
89
79
parameters : vec ! [
90
- Box :: new( ArrayType {
91
- base: Box :: new( AnyType ) ,
92
- } ) ,
93
- Box :: new( DynamicType {
94
- function: first_element_type,
95
- } ) ,
80
+ Box :: new( ArrayType :: new( Box :: new( AnyType ) ) ) ,
81
+ Box :: new( DynamicType :: new( first_element_type) ) ,
96
82
] ,
97
- return_type : Box :: new ( DynamicType {
98
- function : first_element_type,
99
- } ) ,
83
+ return_type : Box :: new ( DynamicType :: new ( first_element_type) ) ,
100
84
} ,
101
85
) ;
102
86
map. insert (
@@ -181,20 +165,18 @@ pub fn array_append(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
181
165
let mut array = inputs[ 0 ] . as_array ( ) . unwrap ( ) ;
182
166
let element = & inputs[ 1 ] ;
183
167
array. push ( element. to_owned ( ) ) ;
184
- Box :: new ( ArrayValue {
185
- values : array,
186
- base_type : inputs[ 0 ] . data_type ( ) . clone ( ) ,
187
- } )
168
+
169
+ let element_type = inputs[ 0 ] . data_type ( ) . clone ( ) ;
170
+ Box :: new ( ArrayValue :: new ( array, element_type) )
188
171
}
189
172
190
173
pub fn array_prepend ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
191
174
let element = & inputs[ 0 ] ;
192
175
let mut array = inputs[ 1 ] . as_array ( ) . unwrap ( ) ;
193
176
array. insert ( 0 , element. clone ( ) ) ;
194
- Box :: new ( ArrayValue {
195
- values : array,
196
- base_type : inputs[ 1 ] . data_type ( ) . clone ( ) ,
197
- } )
177
+
178
+ let element_type = inputs[ 0 ] . data_type ( ) . clone ( ) ;
179
+ Box :: new ( ArrayValue :: new ( array, element_type) )
198
180
}
199
181
200
182
pub fn array_remove ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
@@ -204,10 +186,9 @@ pub fn array_remove(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
204
186
. into_iter ( )
205
187
. filter ( |element| !element_to_remove. equals ( element) )
206
188
. collect ( ) ;
207
- Box :: new ( ArrayValue {
208
- values : array_after_remove,
209
- base_type : inputs[ 0 ] . data_type ( ) . clone ( ) ,
210
- } )
189
+
190
+ let element_type = inputs[ 0 ] . data_type ( ) . clone ( ) ;
191
+ Box :: new ( ArrayValue :: new ( array_after_remove, element_type) )
211
192
}
212
193
213
194
pub fn array_cat ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
@@ -216,16 +197,15 @@ pub fn array_cat(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
216
197
let mut result = Vec :: with_capacity ( first. len ( ) + other. len ( ) ) ;
217
198
result. append ( & mut first) ;
218
199
result. append ( & mut other) ;
219
- Box :: new ( ArrayValue {
220
- values : result,
221
- base_type : inputs[ 0 ] . data_type ( ) . clone ( ) ,
222
- } )
200
+
201
+ let element_type = inputs[ 0 ] . data_type ( ) . clone ( ) ;
202
+ Box :: new ( ArrayValue :: new ( result, element_type) )
223
203
}
224
204
225
205
pub fn array_length ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
226
206
let array = inputs[ 0 ] . as_array ( ) . unwrap ( ) ;
227
207
let value = array. len ( ) as i64 ;
228
- Box :: new ( IntValue { value } )
208
+ Box :: new ( IntValue :: new ( value) )
229
209
}
230
210
231
211
pub fn array_shuffle ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
@@ -235,24 +215,17 @@ pub fn array_shuffle(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
235
215
. downcast_ref :: < ArrayType > ( )
236
216
. unwrap ( )
237
217
. base ;
238
-
239
218
let mut array = inputs[ 0 ] . as_array ( ) . unwrap ( ) ;
240
- array. shuffle ( & mut rand:: thread_rng ( ) ) ;
241
- Box :: new ( ArrayValue {
242
- values : array,
243
- base_type : element_type. clone ( ) ,
244
- } )
219
+ array. shuffle ( & mut rand:: rng ( ) ) ;
220
+ Box :: new ( ArrayValue :: new ( array, element_type. clone ( ) ) )
245
221
}
246
222
247
223
pub fn array_position ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
248
224
let array = inputs[ 0 ] . as_array ( ) . unwrap ( ) ;
249
225
let elemnet = & inputs[ 1 ] ;
250
226
if let Some ( index) = array. iter ( ) . position ( |r| r. equals ( elemnet) ) {
251
- return Box :: new ( IntValue {
252
- value : ( index + 1 ) as i64 ,
253
- } ) ;
227
+ return Box :: new ( IntValue :: new ( ( index + 1 ) as i64 ) ) ;
254
228
}
255
-
256
229
Box :: new ( NullValue )
257
230
}
258
231
@@ -262,22 +235,15 @@ pub fn array_positions(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
262
235
let mut positions: Vec < Box < dyn Value > > = vec ! [ ] ;
263
236
for ( index, element) in array. into_iter ( ) . enumerate ( ) {
264
237
if element. equals ( target) {
265
- positions. push ( Box :: new ( IntValue {
266
- value : ( index + 1 ) as i64 ,
267
- } ) ) ;
238
+ positions. push ( Box :: new ( IntValue :: new ( ( index + 1 ) as i64 ) ) ) ;
268
239
}
269
240
}
270
- Box :: new ( ArrayValue {
271
- values : positions,
272
- base_type : Box :: new ( IntType ) ,
273
- } )
241
+ Box :: new ( ArrayValue :: new ( positions, Box :: new ( IntType ) ) )
274
242
}
275
243
276
244
pub fn array_dims ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
277
245
let array_type = inputs[ 0 ] . data_type ( ) ;
278
- Box :: new ( TextValue {
279
- value : array_type. to_string ( ) ,
280
- } )
246
+ Box :: new ( TextValue :: new ( array_type. to_string ( ) ) )
281
247
}
282
248
283
249
pub fn array_replace ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
@@ -290,11 +256,7 @@ pub fn array_replace(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
290
256
* element = to. clone ( ) ;
291
257
}
292
258
}
293
-
294
- Box :: new ( ArrayValue {
295
- values : array_values,
296
- base_type : array_type,
297
- } )
259
+ Box :: new ( ArrayValue :: new ( array_values, array_type) )
298
260
}
299
261
300
262
pub fn array_trim ( inputs : & [ Box < dyn Value > ] ) -> Box < dyn Value > {
@@ -303,8 +265,5 @@ pub fn array_trim(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
303
265
let array_len = array. len ( ) ;
304
266
let n = i64:: min ( array. len ( ) . try_into ( ) . unwrap ( ) , inputs[ 1 ] . as_int ( ) . unwrap ( ) ) ;
305
267
array. truncate ( array_len - n as usize ) ;
306
- Box :: new ( ArrayValue {
307
- values : array,
308
- base_type : array_type,
309
- } )
268
+ Box :: new ( ArrayValue :: new ( array, array_type) )
310
269
}
0 commit comments