### Arena Tree Operations Source: https://docs.rs/indextree Examples of creating an arena, adding nodes, and performing tree operations like appending. ```APIDOC ## Arena Tree Operations ### Description Demonstrates how to initialize an Arena and perform basic node manipulation such as adding nodes and appending them. ### Request Example ```rust use indextree::Arena; // Create a new arena let arena = &mut Arena::new(); // Add some new nodes to the arena let a = arena.new_node(1); let b = arena.new_node(2); // Append b to a a.append(b, arena); assert_eq!(b.ancestors(arena).count(), 2); ``` ``` -------------------------------- ### Create and Append Nodes in Arena Source: https://docs.rs/indextree Demonstrates the basic usage of creating an arena, adding new nodes, and appending one node to another. Ensure the arena is mutable when performing append operations. ```rust use indextree::Arena; // Create a new arena let arena = &mut Arena::new(); // Add some new nodes to the arena let a = arena.new_node(1); let b = arena.new_node(2); // Append b to a a.append(b, arena); assert_eq!(b.ancestors(arena).count(), 2); ``` -------------------------------- ### Checked Tree Mutation Source: https://docs.rs/indextree Demonstrates error handling using checked variants of tree modification methods. ```APIDOC ## Checked Tree Mutation ### Description Methods that modify the tree come in checked variants that return a Result with a NodeError on failure, preventing panics. ### Request Example ```rust use indextree::{Arena, NodeError}; let mut arena = Arena::new(); let root = arena.new_node("root"); // Cannot append a node to itself assert!(matches!( root.checked_append(root, &mut arena), Err(NodeError::AppendSelf) )); ``` ``` -------------------------------- ### Handle Node Append Errors Source: https://docs.rs/indextree Illustrates how to use the checked variants of tree mutation methods to handle errors, such as attempting to append a node to itself. The `checked_append` method returns a `Result` which can be matched for specific `NodeError` variants. ```rust use indextree::{Arena, NodeError}; let mut arena = Arena::new(); let root = arena.new_node("root"); // Cannot append a node to itself assert!(matches!( root.checked_append(root, &mut arena), Err(NodeError::AppendSelf) )); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.