auto_creation/
auto_creation.rs

1// Example demonstrating the auto-creation feature
2// When you add edges to nodes that don't exist, they are automatically created
3// and shown with angle brackets ⟨⟩ instead of square brackets []
4
5use ascii_dag::graph::DAG;
6
7fn main() {
8    println!("=== Auto-Creation Feature Examples ===\n");
9
10    // Example 1: Missing target node
11    println!("1. Adding edge to missing node (auto-created):");
12    let mut dag = DAG::new();
13    dag.add_node(1, "Defined");
14    dag.add_edge(1, 2); // Node 2 doesn't exist - will be auto-created
15    println!("{}\n", dag.render());
16
17    // Example 2: Both nodes missing
18    println!("2. Both nodes missing (both auto-created):");
19    let mut dag = DAG::new();
20    dag.add_edge(10, 20); // Neither node exists - both will be auto-created
21    println!("{}\n", dag.render());
22
23    // Example 3: Mixed explicit and auto-created
24    println!("3. Mixed defined and auto-created nodes:");
25    let mut dag = DAG::new();
26    dag.add_node(1, "Start");
27    dag.add_node(3, "End");
28    dag.add_edge(1, 2); // Node 2 auto-created
29    dag.add_edge(2, 3); // Node 2 already auto-created, Node 3 exists
30    println!("{}\n", dag.render());
31
32    // Example 4: Complex graph with some auto-created nodes
33    println!("4. Complex graph with auto-created nodes:");
34    let mut dag = DAG::new();
35    dag.add_node(1, "Root");
36    dag.add_node(5, "Leaf");
37    dag.add_edge(1, 2); // 2 auto-created
38    dag.add_edge(1, 3); // 3 auto-created
39    dag.add_edge(2, 4); // 4 auto-created
40    dag.add_edge(3, 4); // 4 already auto-created
41    dag.add_edge(4, 5); // 5 exists
42    println!("{}\n", dag.render());
43
44    println!("Note: Nodes with ⟨⟩ brackets were auto-created.");
45    println!("      Nodes with [] brackets were explicitly defined.");
46}