| Crates.io | wrappedviz |
| lib.rs | wrappedviz |
| version | 0.2.2 |
| created_at | 2025-07-13 02:04:55.896448+00 |
| updated_at | 2025-09-04 21:37:59.052567+00 |
| description | A set of bindings to graphviz C API for rendering graphs |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1749896 |
| size | 22,668,689 |
This crate provides bindings and minimal wrapper types for interacting with C graphviz.
This crate provides an idiomatic Rust wrapper over the Graphviz C libraries (libgvc and libcgraph),
enabling you to create, layout, and render graphs using Graphviz in a safe and ergonomic way.
dot, neato, fdp, etc.)svg, png, dot, json, and many moreserde support for attribute enumsuse graphviz::*;
use graphviz::style::{NodeAttr, GraphAttr, CommonAttr};
use graphviz::style::shape::NodeShape;
fn main() {
let ctx = Context::new();
// Start with an empty directed graph
let mut graph = Graph::new("digraph G {}", &ctx);
// Add nodes A and B
graph.add_node("A");
graph.add_node("B");
graph.add_edge("A", "B", "A_to_B");
// Style node A
graph.set_attr_on_node("A", NodeAttr::Shape(NodeShape::Box)).unwrap();
// Label the edge
graph.set_attr_on_edge("A_to_B", CommonAttr::Label("A to B".into())).unwrap();
// Set graph-level attributes
graph.set_attr_on_graph(GraphAttr::RankDir(style::RankDir::LR)).unwrap();
// Layout the graph using `dot`
graph.set_layout(Layout::Dot);
// Render the graph to SVG format
let svg = ctx.render(&graph, OutputFormat::Svg);
std::fs::write("example.svg", svg).unwrap();
}
While this crate provides a safe wrapper over unsafe C bindings, all Graph objects must be dropped before their parent Context.
serde: Enables serialization and deserialization for enums like Layout, OutputFormat, and attribute types.bindings: Enables native C bindings for the use of graphviz, on by default.Licensed under MIT or Apache-2.0.