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 = NumberInput::default().into_leaf();
let right = NumberInput::default().into_leaf();
let sum = Sum::default().into_node(Components::new(Rc::clone(&left), Rc::clone(&right)));

let graph = MyGraph { left, right, sum };

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.
graph.sum.resolve(&mut visitor);

// A Graphviz representation is now available on the visitor!
assert_eq!(visitor.render().unwrap(), r#"
digraph G {
  0[label="NumberInput"];
  1[label="NumberInput"];
  2[label="Sum"];
  0 -> 2;
  1 -> 2;
}
"#.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) -> boolwhere 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)where N: Identifiable,

Touch the node. 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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.