short version:
What data structure would you use to store a DOM Tree in Rust ?
long version
-
Yes, it is guaranteed that there are no loops. Yes, it's guaranteed that it is directed and acyclic. Yes, it's guaranteed to be a TREE rather than merely a DAG.
-
If all we wanted to do was to store a purely functional tree, we can do something like
pub enum TreeNode {
Div(Vec<TreeNode>),
Span(Vec<TreeNode>),
Br(),
Img(src: String, width: u32, height: u32),
...
}
But the problem wit this approach is that it is hard to get a "pointer to that location" -- i.e. suppose we had opts for:
delete all subtree starting at this node
swap subtres at node1 and node2
... basically, in a "purely functional" approach, it is messy to capture the notion of "that node"
- Now, back to the original question. In Rust, what is the right data structure to use?