1
+ use std:: fmt:: Debug ;
2
+ use std:: hash:: Hash ;
3
+
1
4
use crate :: future_wrapper:: FutureWrapper ;
2
5
use crate :: resolve:: Path ;
3
6
use crate :: Scope ;
4
7
8
+ use super :: { PathContainer , PathContainerWf } ;
9
+
5
10
/// Interface for scope containers that support the operations required for query resolution.
6
- pub trait ScopeContainer < LABEL > {
11
+ pub trait ScopeContainer < ' sg , ' rslv , LABEL : Debug + ' sg , DATA : ' sg > : Debug {
7
12
/// The type containing paths obtained after stepping to this scope.
8
13
type PathContainer ;
9
14
@@ -14,7 +19,95 @@ pub trait ScopeContainer<LABEL> {
14
19
fn lift_step ( self , lbl : LABEL , prefix : Path < LABEL > ) -> Self :: PathContainer ;
15
20
}
16
21
17
- impl < LABEL : Copy > ScopeContainer < LABEL > for Vec < Scope > {
22
+ /// Trait that is auto-implemented for any [ScopeContainer] implementation that yields a valid [PathContainer].
23
+ ///
24
+ /// This trait is implemented for:
25
+ /// - `Vec<Scope>`,
26
+ /// - [Result] of scope containers, and
27
+ /// - [FutureWrapper] of scope containers.
28
+ /// ```
29
+ /// # use scopegraphs::containers::ScopeContainerWf;
30
+ /// # use scopegraphs::future_wrapper::FutureWrapper;
31
+ /// # use scopegraphs::Scope;
32
+ /// # use std::fmt::Debug;
33
+ /// # use std::hash::Hash;
34
+ ///
35
+ /// # trait LBound<'sg>: Copy + Hash + Eq + Debug + 'sg {}
36
+ /// # trait DBound<'sg>: Hash + Eq + 'sg {}
37
+ ///
38
+ /// fn test<'sg, 'rslv, LABEL: LBound<'sg>, DATA: DBound<'sg>, DWFO>(
39
+ /// cont: impl ScopeContainerWf<'sg, 'rslv, LABEL, DATA, DWFO>
40
+ /// ) { }
41
+ ///
42
+ /// # fn scope_vec<'sg, 'rslv, LABEL: LBound<'sg>, DATA: DBound<'sg>>() {
43
+ /// let vec: Vec<Scope> = todo!();
44
+ /// test::<'_, '_, LABEL, DATA, bool>(vec);
45
+ /// # }
46
+ ///
47
+ /// # fn result<'sg, 'rslv, LABEL: LBound<'sg>, DATA: DBound<'sg>, E: Debug + Clone>() {
48
+ /// let result: Result<Vec<Scope>, E> = todo!();
49
+ /// test::<'_, '_, LABEL, DATA, bool>(result);
50
+ /// test::<'_, '_, LABEL, DATA, Result<bool, E>>(result);
51
+ /// # }
52
+ ///
53
+ /// # fn future<'sg, 'rslv, LABEL: LBound<'sg>, DATA: DBound<'sg>>() {
54
+ /// let future: FutureWrapper<Vec<Scope>> = todo!();
55
+ /// test::<'_, '_, LABEL, DATA, bool>(future);
56
+ /// test::<'_, '_, LABEL, DATA, FutureWrapper<'_, bool>>(future);
57
+ /// # }
58
+ /// ```
59
+ ///
60
+ /// ```no_run
61
+ /// # use scopegraphs::containers::ScopeContainerWf;
62
+ /// # use scopegraphs::Scope;
63
+ /// # use std::fmt::Debug;
64
+ /// # use std::hash::Hash;
65
+ ///
66
+ ///
67
+ /// fn test<'sg, 'rslv, LABEL: Hash + Eq + Debug + 'sg, DATA: Hash + Eq + 'sg, DWFO>(cont: impl ScopeContainerWf<'sg, 'rslv, LABEL, DATA, DWFO>) {
68
+ ///
69
+ /// }
70
+ /// ```
71
+ ///
72
+ /// ```no_run
73
+ /// # use scopegraphs::containers::ScopeContainerWf;
74
+ /// # use scopegraphs::Scope;
75
+ /// # use std::fmt::Debug;
76
+ /// # use std::hash::Hash;
77
+ ///
78
+ /// test::<'_, '_, (), (), bool>(Result::<_, ()>::Ok(Vec::<Scope>::new()));
79
+ /// test::<'_, '_, (), (), Result<bool, ()>>(Result::<_, ()>::Ok(Vec::<Scope>::new()));
80
+ ///
81
+ /// fn test<'sg, 'rslv, LABEL: Hash + Eq + Debug + 'sg, DATA: Hash + Eq + 'sg, DWFO>(cont: impl ScopeContainerWf<'sg, 'rslv, LABEL, DATA, DWFO>) {
82
+ ///
83
+ /// }
84
+ /// ```
85
+ ///
86
+ pub trait ScopeContainerWf < ' sg , ' rslv , LABEL , DATA , DWFO > :
87
+ ScopeContainer < ' sg , ' rslv , LABEL , DATA , PathContainer = Self :: PathContainerWf >
88
+ where
89
+ LABEL : Debug + ' sg ,
90
+ DATA : ' sg ,
91
+ {
92
+ /// Refinement of `Self::PathContainer`, carrying proof that this scope container resolves to valid path containers.
93
+ type PathContainerWf : PathContainerWf < ' sg , ' rslv , LABEL , DATA , DWFO > ;
94
+ }
95
+
96
+ impl < ' sg , ' rslv , LABEL , DATA , DWFO , T > ScopeContainerWf < ' sg , ' rslv , LABEL , DATA , DWFO > for T
97
+ where
98
+ LABEL : Debug + ' sg ,
99
+ DATA : ' sg ,
100
+ T : ScopeContainer < ' sg , ' rslv , LABEL , DATA > ,
101
+ Self :: PathContainer : PathContainerWf < ' sg , ' rslv , LABEL , DATA , DWFO > ,
102
+ {
103
+ type PathContainerWf = Self :: PathContainer ;
104
+ }
105
+
106
+ impl < ' sg : ' rslv , ' rslv , LABEL : Debug + Copy + Eq + Hash + ' sg , DATA : Eq + Hash + ' sg >
107
+ ScopeContainer < ' sg , ' rslv , LABEL , DATA > for Vec < Scope >
108
+ where
109
+ Vec < Path < LABEL > > : PathContainer < ' sg , ' rslv , LABEL , DATA > ,
110
+ {
18
111
type PathContainer = Vec < Path < LABEL > > ;
19
112
20
113
fn lift_step ( self , lbl : LABEL , prefix : Path < LABEL > ) -> Self :: PathContainer {
@@ -24,21 +117,36 @@ impl<LABEL: Copy> ScopeContainer<LABEL> for Vec<Scope> {
24
117
}
25
118
}
26
119
27
- impl < LABEL , SC : ScopeContainer < LABEL > , E > ScopeContainer < LABEL > for Result < SC , E > {
120
+ impl <
121
+ ' sg : ' rslv ,
122
+ ' rslv ,
123
+ LABEL : Debug + Copy + Eq + Hash + ' sg ,
124
+ DATA : Eq + Hash + ' sg ,
125
+ SC : ScopeContainer < ' sg , ' rslv , LABEL , DATA > ,
126
+ E : Debug ,
127
+ > ScopeContainer < ' sg , ' rslv , LABEL , DATA > for Result < SC , E >
128
+ where
129
+ Result < SC :: PathContainer , E > : PathContainer < ' sg , ' rslv , LABEL , DATA > ,
130
+ {
28
131
type PathContainer = Result < SC :: PathContainer , E > ;
29
132
30
133
fn lift_step ( self , lbl : LABEL , prefix : Path < LABEL > ) -> Self :: PathContainer {
31
134
self . map ( |sc| sc. lift_step ( lbl, prefix) )
32
135
}
33
136
}
34
137
35
- impl < ' rslv , LABEL , SC : ScopeContainer < LABEL > + Clone > ScopeContainer < LABEL >
36
- for FutureWrapper < ' rslv , SC >
138
+ impl <
139
+ ' sg : ' rslv ,
140
+ ' rslv ,
141
+ LABEL : Debug + Copy + Eq + Hash + ' sg ,
142
+ DATA : Eq + Hash + ' sg ,
143
+ SC : ScopeContainer < ' sg , ' rslv , LABEL , DATA > + Clone ,
144
+ > ScopeContainer < ' sg , ' rslv , LABEL , DATA > for FutureWrapper < ' rslv , SC >
37
145
where
38
146
LABEL : Copy ,
39
- SC :: PathContainer : Clone ,
40
147
Self : ' rslv ,
41
148
LABEL : ' rslv ,
149
+ SC :: PathContainer : Clone ,
42
150
{
43
151
type PathContainer = FutureWrapper < ' rslv , SC :: PathContainer > ;
44
152
0 commit comments