@@ -176,7 +176,57 @@ impl Ord for Value {
176
176
}
177
177
}
178
178
179
+ impl From < String > for Value {
180
+ #[ inline]
181
+ fn from ( s : String ) -> Self {
182
+ Value :: String ( Box :: new ( s) )
183
+ }
184
+ }
185
+
186
+ impl From < & str > for Value {
187
+ #[ inline]
188
+ fn from ( s : & str ) -> Self {
189
+ Value :: String ( Box :: new ( s. to_string ( ) ) )
190
+ }
191
+ }
192
+
193
+ impl From < i64 > for Value {
194
+ #[ inline]
195
+ fn from ( n : i64 ) -> Self {
196
+ Value :: Integer ( n)
197
+ }
198
+ }
199
+
200
+ impl From < f64 > for Value {
201
+ #[ inline]
202
+ fn from ( f : f64 ) -> Self {
203
+ Value :: Real ( OrderedFloat ( f) )
204
+ }
205
+ }
206
+
207
+ impl From < List > for Value {
208
+ #[ inline]
209
+ fn from ( v : List ) -> Self {
210
+ Value :: List ( Box :: new ( v) )
211
+ }
212
+ }
213
+
214
+ impl From < Tuple > for Value {
215
+ #[ inline]
216
+ fn from ( v : Tuple ) -> Self {
217
+ Value :: Tuple ( Box :: new ( v) )
218
+ }
219
+ }
220
+
221
+ impl From < Bag > for Value {
222
+ #[ inline]
223
+ fn from ( v : Bag ) -> Self {
224
+ Value :: Bag ( Box :: new ( v) )
225
+ }
226
+ }
227
+
179
228
#[ derive( Default , Hash , PartialEq , Eq , Clone ) ]
229
+ /// Represents a PartiQL List value, e.g. [1, 2, 'one']
180
230
pub struct List ( Vec < Value > ) ;
181
231
182
232
impl List {
@@ -226,7 +276,7 @@ macro_rules! partiql_list {
226
276
List :: from( vec![ ] )
227
277
) ;
228
278
( $elem: expr; $n: expr) => (
229
- List :: from( vec![ Value :: from( $elem) , $n] )
279
+ List :: from( vec![ Value :: from( $elem) ; $n] )
230
280
) ;
231
281
( $( $x: expr) ,+ $( , ) ?) => (
232
282
List :: from( vec![ $( Value :: from( $x) ) ,+] )
@@ -252,13 +302,6 @@ impl Iterator for ListIntoIterator {
252
302
}
253
303
}
254
304
255
- impl From < List > for Value {
256
- #[ inline]
257
- fn from ( v : List ) -> Self {
258
- Value :: List ( Box :: new ( v) )
259
- }
260
- }
261
-
262
305
impl Debug for List {
263
306
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
264
307
f. debug_list ( ) . entries ( & self . 0 ) . finish ( )
@@ -307,6 +350,7 @@ impl Ord for List {
307
350
}
308
351
309
352
#[ derive( Default , Eq , Clone ) ]
353
+ /// Represents a PartiQL BAG value, e.g.: <<1, 'two', 4>>
310
354
pub struct Bag ( Vec < Value > ) ;
311
355
312
356
impl Bag {
@@ -346,7 +390,7 @@ macro_rules! partiql_bag {
346
390
Bag :: from( vec![ ] )
347
391
) ;
348
392
( $elem: expr; $n: expr) => (
349
- Bag :: from( vec![ Value :: from( $elem) , $n] )
393
+ Bag :: from( vec![ Value :: from( $elem) ; $n] )
350
394
) ;
351
395
( $( $x: expr) ,+ $( , ) ?) => (
352
396
Bag :: from( vec![ $( Value :: from( $x) ) ,+] )
@@ -372,13 +416,6 @@ impl Iterator for BagIntoIterator {
372
416
}
373
417
}
374
418
375
- impl From < Bag > for Value {
376
- #[ inline]
377
- fn from ( v : Bag ) -> Self {
378
- Value :: Bag ( Box :: new ( v) )
379
- }
380
- }
381
-
382
419
impl Debug for Bag {
383
420
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
384
421
write ! ( f, "<<" ) ?;
@@ -444,13 +481,6 @@ where
444
481
}
445
482
}
446
483
447
- impl From < Tuple > for Value {
448
- #[ inline]
449
- fn from ( v : Tuple ) -> Self {
450
- Value :: Tuple ( Box :: new ( v) )
451
- }
452
- }
453
-
454
484
#[ macro_export]
455
485
macro_rules! partiql_tuple {
456
486
( ) => (
@@ -517,34 +547,6 @@ impl Hash for Tuple {
517
547
}
518
548
}
519
549
520
- impl From < String > for Value {
521
- #[ inline]
522
- fn from ( s : String ) -> Self {
523
- Value :: String ( Box :: new ( s) )
524
- }
525
- }
526
-
527
- impl From < & str > for Value {
528
- #[ inline]
529
- fn from ( s : & str ) -> Self {
530
- Value :: String ( Box :: new ( s. to_string ( ) ) )
531
- }
532
- }
533
-
534
- impl From < i64 > for Value {
535
- #[ inline]
536
- fn from ( n : i64 ) -> Self {
537
- Value :: Integer ( n)
538
- }
539
- }
540
-
541
- impl From < f64 > for Value {
542
- #[ inline]
543
- fn from ( f : f64 ) -> Self {
544
- Value :: Real ( OrderedFloat ( f) )
545
- }
546
- }
547
-
548
550
#[ cfg( test) ]
549
551
mod tests {
550
552
use super :: * ;
@@ -578,4 +580,15 @@ mod tests {
578
580
println ! ( "Cow<Value> size: {}" , mem:: size_of:: <Cow <Value >>( ) ) ;
579
581
println ! ( "Cow<&Value> size: {}" , mem:: size_of:: <Cow <& Value >>( ) ) ;
580
582
}
583
+
584
+ #[ test]
585
+ fn macro_rules_tests ( ) {
586
+ println ! ( "partiql_list:{:?}" , partiql_list!( ) ) ;
587
+ println ! ( "partiql_list:{:?}" , partiql_list![ 10 , 10 ] ) ;
588
+ println ! ( "partiql_list:{:?}" , partiql_list!( 5 ; 3 ) ) ;
589
+ println ! ( "partiql_bag:{:?}" , partiql_bag!( ) ) ;
590
+ println ! ( "partiql_bag:{:?}" , partiql_bag![ 10 , 10 ] ) ;
591
+ println ! ( "partiql_bag:{:?}" , partiql_bag!( 5 ; 3 ) ) ;
592
+ println ! ( "partiql_tuple:{:?}" , partiql_tuple![ ( "a" , 1 ) , ( "b" , 2 ) ] ) ;
593
+ }
581
594
}
0 commit comments