I have a tree and I want each node of the tree to have a pointer to its parent.
struct DataDeclaration {
parent: Option<Arc<DataDeclaration>>,
children: Option<Vec<Weak<DataDeclaration>>>,
properties: HashMap<Identifier, DataDeclarationProperty>,
}
This creates a cycle, so I use Weak
to make sure the memory doesn’t live indefinitely. This tree will be immutable for the entire length of my application except, of course, when the tree is constructed.
In order to create this tree, do I need to use a Mutex
or RwLock
from the standard library or parking_lot
? Will there be a negative performance impact if I only use the lock for reads?