Crate ascii_dag

Crate ascii_dag 

Source
Expand description

§ascii-dag

Modular ASCII DAG (Directed Acyclic Graph) renderer for error chains, build systems, and dependency visualization.

§Features

  • Tiny: ~77KB WASM (minimal), ~41KB without generic features
  • Fast: Cached adjacency lists, O(1) lookups, zero-copy rendering
  • no_std: Works in embedded/WASM environments
  • Modular: Each component can be used independently
  • Safe: Cycle detection built-in

§Performance

  • Cached Adjacency Lists: O(1) child/parent lookups (not O(E))
  • Zero Allocations: Direct buffer writes with write_node()
  • HashMap Indexing: O(1) ID→index instead of O(N) scans

§Feature Flags

  • std (default): Standard library support
  • generic (default): Generic algorithms (cycle detection, topological sort, impact analysis, metrics)
  • warnings: Debug warnings for auto-created nodes

To minimize bundle size, disable generic:

ascii-dag = { version = "0.1", default-features = false, features = ["std"] }

§Quick Start

use ascii_dag::graph::{DAG, RenderMode};

// Batch construction (fast!)
let dag = DAG::from_edges(
    &[(1, "Error1"), (2, "Error2"), (3, "Error3")],
    &[(1, 2), (2, 3)]
);

println!("{}", dag.render());

§Modular Design

The library is organized into separate, independently-usable modules:

§graph - Core DAG Structure

use ascii_dag::graph::DAG;

let mut dag = DAG::new();
dag.add_node(1, "A");
dag.add_node(2, "B");
dag.add_edge(1, 2);

§cycles - Cycle Detection

use ascii_dag::graph::DAG;

let mut dag = DAG::new();
dag.add_edge(1, 2);
dag.add_edge(2, 1);
assert!(dag.has_cycle());

§cycles::generic - Generic Cycle Detection

Works with any data structure via higher-order functions:

use ascii_dag::cycles::generic::detect_cycle_fn;

let get_deps = |id: &usize| match id {
    1 => vec![2],
    2 => vec![3],
    _ => vec![],
};

let cycle = detect_cycle_fn(&[1, 2, 3], get_deps);
assert!(cycle.is_none());

§layout::generic - Generic Topological Sorting

Sort any dependency graph into execution order:

use ascii_dag::layout::generic::topological_sort_fn;

let get_deps = |task: &&str| match *task {
    "deploy" => vec!["build"],
    "build" => vec!["compile"],
    "compile" => vec![],
    _ => vec![],
};

let sorted = topological_sort_fn(&["deploy", "compile", "build"], get_deps).unwrap();
// Result: ["compile", "build", "deploy"]
assert_eq!(sorted[0], "compile");

§layout - Graph Layout Algorithms

Sugiyama hierarchical layout for positioning nodes.

§render - ASCII Rendering

Vertical, horizontal, and cycle visualization modes.

Re-exports§

pub use graph::DAG;
pub use graph::RenderMode;

Modules§

cycles
Cycle detection algorithms for directed graphs.
graph
Core DAG (Directed Acyclic Graph) data structure.
layout
Graph layout algorithms for hierarchical rendering.
render
ASCII rendering for DAG visualization.