1
+ use crate :: completeness:: FutureCompleteness ;
1
2
use crate :: {
2
3
completeness:: private:: Sealed ,
3
4
completeness:: {
@@ -20,6 +21,7 @@ use std::{collections::HashSet, hash::Hash};
20
21
///
21
22
/// Returns [`Delay`] when edges are retrieved (e.g. during query resolution) for an edge that is
22
23
/// not yet closed.
24
+ #[ derive( Debug ) ]
23
25
pub struct ExplicitClose < LABEL > {
24
26
critical_edges : CriticalEdgeSet < LABEL > ,
25
27
}
@@ -189,3 +191,86 @@ impl<LABEL: Hash + Eq, DATA> ScopeGraph<LABEL, DATA, ExplicitClose<LABEL>> {
189
191
self . completeness . close ( scope, label)
190
192
}
191
193
}
194
+
195
+ impl < LABEL : Hash + Eq + Copy , DATA > ScopeGraph < LABEL , DATA , FutureCompleteness < LABEL > > {
196
+ /// TODO: update this example to use futures
197
+ /// Closes an edge, (i.e., prohibit future new
198
+ ///
199
+ /// For example, the following program will return an error.
200
+ /// ```
201
+ /// # use scopegraphs_lib::completeness::ExplicitClose;
202
+ /// # use scopegraphs_lib::ScopeGraph;
203
+ /// # use scopegraphs_macros::Label;
204
+ /// # #[derive(Eq, Hash, PartialEq, Label)] enum Lbl { Def }
205
+ /// # use Lbl::*;
206
+ /// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
207
+ ///
208
+ /// let s1 = sg.add_scope_with(0, [Def]);
209
+ /// let s2 = sg.add_scope_closed(42);
210
+ ///
211
+ /// sg.close(s1, &Def);
212
+ /// sg.add_edge(s1, Def, s2).expect_err("cannot add edge after closing edge");
213
+ /// ```
214
+ ///
215
+ /// Closing is required to permit queries to traverse these edges:
216
+ /// ```
217
+ ///
218
+ /// # use scopegraphs_lib::completeness::ExplicitClose;
219
+ /// # use scopegraphs_lib::ScopeGraph;
220
+ /// # use scopegraphs_lib::resolve::{DefaultDataEquiv, DefaultLabelOrder, EdgeOrData, Resolve};
221
+ /// # use scopegraphs_macros::{compile_regex, Label};
222
+ /// #
223
+ /// # #[derive(Eq, Hash, PartialEq, Label, Debug, Copy, Clone)]
224
+ /// # enum Lbl { Def }
225
+ /// # use Lbl::*;
226
+ /// # type LblD = EdgeOrData<Lbl>;
227
+ /// #
228
+ /// # compile_regex!(type Regex<Lbl> = Def);
229
+ /// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
230
+ ///
231
+ /// let s1 = sg.add_scope_with(0, [Def]);
232
+ /// let s2 = sg.add_scope_closed(42);
233
+ ///
234
+ /// // Note: not calling `sg.close(s1, &Def)`
235
+ ///
236
+ /// let query_result = sg.query()
237
+ /// .with_path_wellformedness(Regex::new()) // regex: `Def`
238
+ /// .with_data_wellformedness(|x: &usize| *x == 42) // match `42`
239
+ /// .resolve(s1);
240
+ ///
241
+ /// query_result.expect_err("require s1/Def to be closed");
242
+ /// ```
243
+ ///
244
+ /// Closing allows queries to resolve:
245
+ /// ```
246
+ ///
247
+ /// # use scopegraphs_lib::completeness::ExplicitClose;
248
+ /// # use scopegraphs_lib::ScopeGraph;
249
+ /// # use scopegraphs_lib::resolve::{DefaultDataEquiv, DefaultLabelOrder, EdgeOrData, Resolve};
250
+ /// # use scopegraphs_macros::{compile_regex, Label};
251
+ /// #
252
+ /// # #[derive(Eq, Hash, PartialEq, Label, Debug, Copy, Clone)]
253
+ /// # enum Lbl { Def }
254
+ /// # use Lbl::*;
255
+ /// # type LblD = EdgeOrData<Lbl>;
256
+ /// #
257
+ /// # compile_regex!(type Regex<Lbl> = Def);
258
+ /// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
259
+ ///
260
+ /// let s1 = sg.add_scope_with(0, [Def]);
261
+ /// let s2 = sg.add_scope_closed(42);
262
+ ///
263
+ /// // Note: closing the edge *after* creating all edges, *before* doing the query
264
+ /// sg.close(s1, &Def);
265
+ ///
266
+ /// let query_result = sg.query()
267
+ /// .with_path_wellformedness(Regex::new()) // regex: `Def`
268
+ /// .with_data_wellformedness(|x: &usize| *x == 42) // match `42`
269
+ /// .resolve(s1);
270
+ ///
271
+ /// query_result.expect("query should return result");
272
+ /// ```
273
+ pub fn close ( & self , scope : Scope , label : & LABEL ) {
274
+ self . completeness . close ( scope, label)
275
+ }
276
+ }
0 commit comments