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§

source§

impl GraphvizVisitor

source

pub fn new() -> Self

source

pub fn render(&self) -> Option<String>

Render the visited graph to Graphviz DOT format. Returns Option::None if no graph has been visited.

Trait Implementations§

source§

impl Debug for GraphvizVisitor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GraphvizVisitor

source§

fn default() -> GraphvizVisitor

Returns the “default value” for a type. Read more
source§

impl Visitor for GraphvizVisitor

§

type Hasher = DefaultHasher

source§

fn visit<N>(&mut self, node: &N) -> bool
where N: Identifiable,

Return true iff this node hasn’t been visited yet.
source§

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,

Touch the node. Useful for building graph visualisations.
source§

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,

Undo a touch. Useful for building graph visualisations.
source§

fn hasher(&self) -> Self::Hasher

source§

fn notify_recalculated<N>(&mut self, _node: &N)
where N: Identifiable,

For diagnostics, notify that a node has been recalculated.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.