hedel-rs
A Hierarchical Doubly Linked List
Hedel-rs provides all you need to create your own abstraction over a
hierarchical doubly linked list in Rust, suitable choice for a DOM tree.
Designed for when you need a nested generation of nodes. ( e.g with macros node!(1, node!(2)) )
Based on Rc, Weak, and a safe wrapper around UnsafeCell (HedelCell).
If you are new to linked lists, consider reading Learn Rust With Entirely Too Many Linked Lists
Ideology
Hedel isn't exactly a tree structure.
NodeListis a wrap around its first node. There isn't any root. This allows for sibling nodes at the root-level.NodeListalso dereferences to its firt node letting you callNode's methods.Nodeis a pointer to its content and other pointers to allow navigation. Those pointers are:parent,child,prevandnext, where child is a pointer to its first child.- Support for node generation using macros: you can use node!(1) and nest how many nodes you want.
Features
-
HedelCell: a cell structure safely relying on UnsafeCell, similar toRefCellbut smaller in size. -
Node/WeakNode: to avoid memory-leaking we also provide a weak version ofNode. -
Macros: generate nodes blazingly fast with node!() and list!()
let node = node!; let my_node = node!; let my_list = list!; -
Identify and compare: create your own identifier implementing the
CompareNodetrait. -
Collect: iterate over the linked list and collect only the nodes matching the identifier.
let node = node!; let collection = node.collect_children; for node in collection.into_iter -
Detach: detach the nodes matching an identifier in the linked list.
let node = node!; let three = node.find_child.unwrap; three.detach; assert_eq!; -
Insert or Append: insert a node at any position in a linked list.
let node = node!; node.insert_child; assert_eq!; node.append_child; assert_eq!;