1
1
#![ deny( rust_2018_idioms) ]
2
2
#![ deny( clippy:: all) ]
3
3
4
+ use derivative:: Derivative ;
5
+ use indexmap:: IndexSet ;
4
6
use itertools:: Itertools ;
5
7
use miette:: Diagnostic ;
6
- use std:: collections:: BTreeSet ;
7
8
use std:: fmt:: { Debug , Display , Formatter } ;
8
- use std:: hash:: Hash ;
9
+ use std:: hash:: { Hash , Hasher } ;
9
10
use thiserror:: Error ;
10
11
11
12
#[ derive( Debug , Clone , Eq , PartialEq , Hash , Error , Diagnostic ) ]
@@ -23,6 +24,16 @@ pub trait Type {}
23
24
24
25
impl Type for StaticType { }
25
26
27
+ fn indexset_hash < H , T > ( set : & IndexSet < T > , state : & mut H )
28
+ where
29
+ H : Hasher ,
30
+ T : Hash ,
31
+ {
32
+ for val in set {
33
+ val. hash ( state)
34
+ }
35
+ }
36
+
26
37
#[ macro_export]
27
38
macro_rules! dynamic {
28
39
( ) => {
@@ -140,7 +151,7 @@ macro_rules! undefined {
140
151
}
141
152
142
153
/// Represents a PartiQL Shape
143
- #[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
154
+ #[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
144
155
// With this implementation `Dynamic` and `AnyOf` cannot have `nullability`; this does not mean their
145
156
// `null` value at runtime cannot belong to their domain.
146
157
// TODO adopt the correct model Pending PartiQL Types semantics finalization: https://github.com/partiql/partiql-lang/issues/18
@@ -151,13 +162,13 @@ pub enum PartiqlShape {
151
162
Undefined ,
152
163
}
153
164
154
- #[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
165
+ #[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
155
166
pub struct StaticType {
156
167
ty : Static ,
157
168
nullable : bool ,
158
169
}
159
170
160
- #[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
171
+ #[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
161
172
pub enum Static {
162
173
// Scalar Types
163
174
Int ,
@@ -506,15 +517,17 @@ impl Display for PartiqlShape {
506
517
}
507
518
}
508
519
509
- #[ derive( Hash , Eq , PartialEq , Debug , Clone , Ord , PartialOrd ) ]
520
+ #[ derive( Derivative , Eq , Debug , Clone ) ]
521
+ #[ derivative( PartialEq , Hash ) ]
510
522
#[ allow( dead_code) ]
511
523
pub struct AnyOf {
512
- types : BTreeSet < PartiqlShape > ,
524
+ #[ derivative( Hash ( hash_with = "indexset_hash" ) ) ]
525
+ types : IndexSet < PartiqlShape > ,
513
526
}
514
527
515
528
impl AnyOf {
516
529
#[ must_use]
517
- pub const fn new ( types : BTreeSet < PartiqlShape > ) -> Self {
530
+ pub const fn new ( types : IndexSet < PartiqlShape > ) -> Self {
518
531
AnyOf { types }
519
532
}
520
533
@@ -531,15 +544,17 @@ impl FromIterator<PartiqlShape> for AnyOf {
531
544
}
532
545
}
533
546
534
- #[ derive( Debug , Clone , Hash , PartialEq , Eq , Ord , PartialOrd ) ]
547
+ #[ derive( Derivative , Eq , Debug , Clone ) ]
548
+ #[ derivative( PartialEq , Hash ) ]
535
549
#[ allow( dead_code) ]
536
550
pub struct StructType {
537
- constraints : BTreeSet < StructConstraint > ,
551
+ #[ derivative( Hash ( hash_with = "indexset_hash" ) ) ]
552
+ constraints : IndexSet < StructConstraint > ,
538
553
}
539
554
540
555
impl StructType {
541
556
#[ must_use]
542
- pub fn new ( constraints : BTreeSet < StructConstraint > ) -> Self {
557
+ pub fn new ( constraints : IndexSet < StructConstraint > ) -> Self {
543
558
StructType { constraints }
544
559
}
545
560
@@ -551,7 +566,7 @@ impl StructType {
551
566
}
552
567
553
568
#[ must_use]
554
- pub fn fields ( & self ) -> BTreeSet < StructField > {
569
+ pub fn fields ( & self ) -> IndexSet < StructField > {
555
570
self . constraints
556
571
. iter ( )
557
572
. flat_map ( |c| {
@@ -575,17 +590,18 @@ impl StructType {
575
590
}
576
591
}
577
592
578
- #[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
593
+ #[ derive( Derivative , Eq , Debug , Clone ) ]
594
+ #[ derivative( PartialEq , Hash ) ]
579
595
#[ allow( dead_code) ]
580
596
#[ non_exhaustive]
581
597
pub enum StructConstraint {
582
598
Open ( bool ) ,
583
599
Ordered ( bool ) ,
584
600
DuplicateAttrs ( bool ) ,
585
- Fields ( BTreeSet < StructField > ) ,
601
+ Fields ( # [ derivative ( Hash ( hash_with = "indexset_hash" ) ) ] IndexSet < StructField > ) ,
586
602
}
587
603
588
- #[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
604
+ #[ derive( Debug , Clone , Hash , Eq , PartialEq ) ]
589
605
#[ allow( dead_code) ]
590
606
pub struct StructField {
591
607
optional : bool ,
@@ -648,7 +664,8 @@ impl From<(&str, PartiqlShape, bool)> for StructField {
648
664
}
649
665
}
650
666
651
- #[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
667
+ #[ derive( Derivative , Eq , Debug , Clone ) ]
668
+ #[ derivative( PartialEq , Hash ) ]
652
669
#[ allow( dead_code) ]
653
670
pub struct BagType {
654
671
element_type : Box < PartiqlShape > ,
@@ -671,7 +688,8 @@ impl BagType {
671
688
}
672
689
}
673
690
674
- #[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
691
+ #[ derive( Derivative , Eq , Debug , Clone ) ]
692
+ #[ derivative( PartialEq , Hash ) ]
675
693
#[ allow( dead_code) ]
676
694
pub struct ArrayType {
677
695
element_type : Box < PartiqlShape > ,
0 commit comments