1 //! Code for debugging the dep-graph.
3 use super::dep_node::DepNode;
6 /// A dep-node filter goes from a user-defined string to a query over
7 /// nodes. Right now the format is like this:
11 /// where the format-string of the dep-node must contain `x`, `y`, and
14 pub struct DepNodeFilter {
19 pub fn new(text: &str) -> Self {
20 DepNodeFilter { text: text.trim().to_string() }
23 /// Returns `true` if all nodes always pass the filter.
24 pub fn accepts_all(&self) -> bool {
28 /// Tests whether `node` meets the filter, returning true if so.
29 pub fn test(&self, node: &DepNode) -> bool {
30 let debug_str = format!("{:?}", node);
31 self.text.split('&').map(|s| s.trim()).all(|f| debug_str.contains(f))
35 /// A filter like `F -> G` where `F` and `G` are valid dep-node
36 /// filters. This can be used to test the source/target independently.
37 pub struct EdgeFilter {
38 pub source: DepNodeFilter,
39 pub target: DepNodeFilter,
43 pub fn new(test: &str) -> Result<EdgeFilter, Box<dyn Error>> {
44 let parts: Vec<_> = test.split("->").collect();
46 Err(format!("expected a filter like `a&b -> c&d`, not `{}`", test).into())
49 source: DepNodeFilter::new(parts[0]),
50 target: DepNodeFilter::new(parts[1]),
55 pub fn test(&self, source: &DepNode, target: &DepNode) -> bool {
56 self.source.test(source) && self.target.test(target)