Struct depends::graphviz::GraphvizVisitor
source · pub struct GraphvizVisitor { /* private fields */ }
Available on crate feature
graphviz
only.Expand description
A Visitor which builds a Graphviz
representation of a given graph.
use depends::graphviz::GraphvizVisitor;
// Compose a graph.
let left = InputNode::new(NumberValue::default());
let left_squared = DerivedNode::new(
Dependency::new(Rc::clone(&left)),
Square,
NumberValue::default(),
);
let right = InputNode::new(NumberValue::default());
let two_numbers = TwoNumbers::init(left_squared, right);
let sum = DerivedNode::new(two_numbers, Add, NumberValue::default());
let sum_squared = DerivedNode::new(Dependency::new(sum), Square, NumberValue::default());
let mut visitor = GraphvizVisitor::new();
// Resolve the graph with this visitor.
// Be sure NOT to use `resolve_root`, as this will clear the visitor's state.
sum_squared.resolve(&mut visitor).unwrap();
println!("{}", visitor.render().unwrap());
// A Graphviz representation is now available on the visitor!
assert_eq!(
visitor.render().unwrap(),
r#"
digraph Dag {
node_0 [label="NumberValue"];
node_1 [label="NumberValue"];
node_0 -> node_1 [label="Square"];
node_2 [label="NumberValue"];
node_3 [label="NumberValue"];
node_1 -> node_3 [label="Add", class="TwoNumbersDep"];
node_2 -> node_3 [label="Add", class="TwoNumbersDep"];
node_4 [label="NumberValue"];
node_3 -> node_4 [label="Square"];
}
"#
.trim()
);
Implementations§
Trait Implementations§
source§impl Debug for GraphvizVisitor
impl Debug for GraphvizVisitor
source§impl Default for GraphvizVisitor
impl Default for GraphvizVisitor
source§fn default() -> GraphvizVisitor
fn default() -> GraphvizVisitor
Returns the “default value” for a type. Read more
source§impl Visitor for GraphvizVisitor
impl Visitor for GraphvizVisitor
type Hasher = DefaultHasher
source§fn visit<N>(&mut self, node: &N) -> boolwhere
N: Identifiable,
fn visit<N>(&mut self, node: &N) -> boolwhere
N: Identifiable,
Return true iff this node hasn’t been visited yet.
source§fn clear(&mut self)
fn clear(&mut self)
Clear the internal collection, prompting this visitor to revisit all
nodes on the next traversal.
source§fn touch<N>(&mut self, node: &N, operation: Option<&'static str>)where
N: Identifiable,
fn touch<N>(&mut self, node: &N, operation: Option<&'static str>)where
N: Identifiable,
Touch the node. Useful for building graph visualisations.
source§fn touch_dependency_group(&mut self, dep: &'static str)
fn touch_dependency_group(&mut self, dep: &'static str)
Touch a dependency group type. Useful for building graph visualisations.
source§fn leave<N>(&mut self, node: &N)where
N: Identifiable,
fn leave<N>(&mut self, node: &N)where
N: Identifiable,
Undo a touch. Useful for building graph visualisations.
fn hasher(&self) -> Self::Hasher
source§fn notify_recalculated<N>(&mut self, _node: &N)where
N: Identifiable,
fn notify_recalculated<N>(&mut self, _node: &N)where
N: Identifiable,
For diagnostics, notify that a node has been recalculated.
Auto Trait Implementations§
impl RefUnwindSafe for GraphvizVisitor
impl Send for GraphvizVisitor
impl Sync for GraphvizVisitor
impl Unpin for GraphvizVisitor
impl UnwindSafe for GraphvizVisitor
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more