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 {
21 text: text.trim().to_string()
25 /// True if all nodes always pass the filter.
26 pub fn accepts_all(&self) -> bool {
30 /// Tests whether `node` meets the filter, returning true if so.
31 pub fn test(&self, node: &DepNode) -> bool {
32 let debug_str = format!("{:?}", node);
35 .all(|f| debug_str.contains(f))
39 /// A filter like `F -> G` where `F` and `G` are valid dep-node
40 /// filters. This can be used to test the source/target independently.
41 pub struct EdgeFilter {
42 pub source: DepNodeFilter,
43 pub target: DepNodeFilter,
47 pub fn new(test: &str) -> Result<EdgeFilter, Box<dyn Error>> {
48 let parts: Vec<_> = test.split("->").collect();
50 Err(format!("expected a filter like `a&b -> c&d`, not `{}`", test).into())
53 source: DepNodeFilter::new(parts[0]),
54 target: DepNodeFilter::new(parts[1]),
63 self.source.test(source) && self.target.test(target)