Struct Graph

Source
pub struct Graph { /* private fields */ }
Expand description

A GraphViz graph structure with RAII-based memory management.

Implementations§

Source§

impl Graph

Source

pub fn new(name: &str, directed: bool) -> Result<Self, GraphvizError>

Creates a new GraphViz graph with the specified name and direction.

§Arguments
  • name - The name of the graph
  • directed - Whether the graph is directed or undirected
§Returns

A Result containing the new Graph or an error

Source

pub fn new_with_strictness( name: &str, directed: bool, strict: bool, ) -> Result<Self, GraphvizError>

Creates a new GraphViz graph with the specified name, direction, and strictness.

Strict graphs do not allow multiple edges between the same pair of nodes.

§Arguments
  • name - The name of the graph
  • directed - Whether the graph is directed or undirected
  • strict - Whether the graph is strict (no duplicate edges)
§Returns

A Result containing the new Graph or an error

Source

pub fn builder(name: &str) -> GraphBuilder

Creates a new builder for configuring and creating a graph.

§Arguments
  • name - The name of the graph to create
§Returns

A GraphBuilder instance

Source

pub fn add_node(&self, name: &str) -> Result<Node<'_>, GraphvizError>

Adds a node to the graph with the specified name.

§Arguments
  • name - The name of the node
§Returns

A Result containing the new Node or an error

Source

pub fn create_node(&self, name: &str) -> NodeBuilder<'_>

Creates a builder for configuring and adding a node.

§Arguments
  • name - The name of the node to create
§Returns

A NodeBuilder instance

Source

pub fn add_edge( &self, from: &Node<'_>, to: &Node<'_>, name: Option<&str>, ) -> Result<Edge<'_>, GraphvizError>

Adds an edge between two nodes, optionally with a name.

§Arguments
  • from - The source node
  • to - The target node
  • name - Optional name for the edge
§Returns

A Result containing the new Edge or an error

Source

pub fn create_edge<'a>( &'a self, from: &'a Node<'_>, to: &'a Node<'_>, name: Option<&str>, ) -> EdgeBuilder<'a>

Creates a builder for configuring and adding an edge.

§Arguments
  • from - The source node
  • to - The target node
  • name - Optional name for the edge
§Returns

An EdgeBuilder instance

Source

pub fn get_node(&self, name: &str) -> Result<Option<Node<'_>>, GraphvizError>

Gets a node by name, returning None if the node doesn’t exist.

§Arguments
  • name - The name of the node to find
§Returns

Option containing the node if found

Source

pub fn find_edge(&self, from: &Node<'_>, to: &Node<'_>) -> Option<Edge<'_>>

Finds an edge between two nodes, returning None if it doesn’t exist.

§Arguments
  • from - The source node
  • to - The target node
§Returns

Option containing the edge if found

Source

pub fn nodes(&self) -> NodeIter<'_>

Creates an iterator over all nodes in the graph.

§Returns

A NodeIter that iterates over all nodes

Source

pub fn edges(&self) -> EdgeIter<'_>

Creates an iterator over all edges in the graph.

§Returns

An EdgeIter that iterates over all edges

Source

pub fn out_edges<'a>(&'a self, node: &'a Node<'_>) -> EdgeIter<'a>

Creates an iterator over all outgoing edges from a node.

§Arguments
  • node - The node to get outgoing edges from
§Returns

An EdgeIter that iterates over outgoing edges

Source

pub fn in_edges<'a>(&'a self, node: &'a Node<'_>) -> EdgeIter<'a>

Creates an iterator over all incoming edges to a node.

§Arguments
  • node - The node to get incoming edges to
§Returns

An EdgeIter that iterates over incoming edges

Source

pub fn node_count(&self) -> i32

Gets the number of nodes in the graph.

§Returns

The number of nodes in the graph

Source

pub fn edge_count(&self) -> i32

Gets the number of edges in the graph.

§Returns

The number of edges in the graph

Source

pub fn set_attribute( &self, name: &str, value: &str, ) -> Result<(), GraphvizError>

Sets an attribute on the graph.

§Arguments
  • name - The attribute name
  • value - The attribute value
§Returns

Result indicating success or failure

Source

pub fn get_attribute(&self, name: &str) -> Result<Option<String>, GraphvizError>

Gets an attribute value from the graph.

§Arguments
  • name - The attribute name
§Returns

Option containing the attribute value if it exists

Source

pub fn remove_node(&self, node: Node<'_>) -> Result<(), GraphvizError>

Removes a node from the graph.

§Arguments
  • node - The node to remove
§Returns

Result indicating success or failure

Source

pub fn remove_edge(&self, edge: Edge<'_>) -> Result<(), GraphvizError>

Removes an edge from the graph.

§Arguments
  • edge - The edge to remove
§Returns

Result indicating success or failure

Source

pub fn name(&self) -> Result<String, GraphvizError>

Gets the name of the graph.

§Returns

The name of the graph as a String

Source

pub fn is_directed(&self) -> bool

Checks if the graph is directed.

§Returns

true if the graph is directed, false otherwise

Source

pub fn is_strict(&self) -> bool

Checks if the graph is strict (no duplicate edges).

§Returns

true if the graph is strict, false otherwise

Trait Implementations§

Source§

impl AttributeContainer for Graph

Source§

fn set_attribute(&self, name: &str, value: &str) -> Result<(), GraphvizError>

Sets an attribute on the container. Read more
Source§

fn get_attribute(&self, name: &str) -> Result<Option<String>, GraphvizError>

Gets an attribute value from the container. Read more
Source§

fn has_attribute(&self, name: &str) -> Result<bool, GraphvizError>

Checks if an attribute exists on the container. Read more
Source§

fn set_attribute_if_absent( &self, name: &str, value: &str, ) -> Result<(), GraphvizError>

Sets an attribute if it doesn’t already exist. Read more
Source§

fn remove_attribute(&self, name: &str) -> Result<(), GraphvizError>

Removes an attribute if it exists. Read more
Source§

impl Drop for Graph

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl !Send for Graph

§

impl !Sync for Graph

§

impl Unpin for Graph

§

impl UnwindSafe for Graph

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>,

Source§

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>,

Source§

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.