module_util/evaluator/mod.rs
1//! Generic [`Evaluator`] interface.
2//!
3//! Evaluator implementations:
4//!
5//! - [`Dfs`]
6
7pub mod imports;
8pub use self::imports::Imports;
9
10pub mod trace;
11pub use self::trace::Trace;
12
13pub mod dfs;
14pub use self::dfs::Dfs;
15
16#[cfg(feature = "std")]
17pub mod metrics;
18#[cfg(feature = "std")]
19pub use self::metrics::Metrics;
20
21#[cfg(feature = "std")]
22pub mod acyclic;
23#[cfg(feature = "std")]
24pub use self::acyclic::Acyclic;
25
26///////////////////////////////////////////////////////////////////////////////
27
28/// An evaluator.
29///
30/// An evaluator is the main mechanism with which [`Merge`] is utilized. The
31/// goal of the [`Evaluator`] is to [`Merge`] modules which may of may not
32/// import other modules.
33///
34/// [`Merge`]: module::merge::Merge
35pub trait Evaluator {
36 /// Id of a module.
37 ///
38 /// This can be anything that can uniquely identify a module. For example,
39 /// a filesystem path.
40 type Id;
41
42 /// The type of the module.
43 type Module;
44
45 /// Evaluation error.
46 type Error;
47
48 /// Check whether the evaluator has evaluated any modules.
49 fn is_empty(&self) -> bool;
50
51 /// Get the next module in evaluation order.
52 ///
53 /// Evaluation order is implementation-specific. An implementation might
54 /// choose to evaluate modules in DFS, BFS or some other unspecified order.
55 /// Returns [`None`] when there are no modules left to evaluate.
56 fn next(&mut self) -> Option<Self::Id>;
57
58 /// Evaluate `module` identified by `id` that imports the modules specified
59 /// by `imports`.
60 fn eval(
61 &mut self,
62 id: Self::Id,
63 imports: Imports<Self::Id>,
64 module: Self::Module,
65 ) -> Result<(), Self::Error>;
66
67 /// Destruct the evaluator and get the final value.
68 ///
69 /// Returns [`None`] when no modules have been evaluated.
70 fn finish(self) -> Option<Self::Module>;
71}