DEV Community

Discussion on: No More Tears, No More Knots: Arena-Allocated Trees in Rust

Collapse
 
deciduously profile image
Ben Lovy

Hi - because all nodes only refer to each other via a Copy index, instead of directly pointing to each other, you should be able to set up such structures without even needing to wrap in Rc. The nodes are only accessed via the arena as needed, the only reference to them is just a number that can be passed around without issue.

Collapse
 
frolovdev profile image
Andrey Frolov

Thank you for the clarification

Thread Thread
 
deciduously profile image
Ben Lovy

The caveat would be simultaneous access - you would need to employ a lock of some sort if you expect multiple threads or tasks to mutably borrow the data in a given node.