pub struct VoxelTree<T: Display> { /* private fields */ }Expand description
This struct is used to own a [NodeData] inside an Arc. The Arc
can be shared, so that it can have multiple owners. It does not have
getter methods for [NodeData]’s properties, instead it implements the
Deref trait to allow it to be used as a [NodeData].
- This library is inspired by r3bl-org work
§Shared ownership
After an instance of this struct is created and it’s internal reference is cloned (and given to another) dropping this instance will not drop the cloned internal reference.
VoxelTree { arc_ref: Arc<NodeData> }
▲ ▲
│ │
│ This atomic ref owns the
│ `NodeData` & is shared
│
1. Has methods to manipulate nodes and their children.
2. When it is dropped, if there are other `Arc`s (shared via
`get_copy_of_internal_arc()`) pointing to the same underlying
`NodeData`, then the `NodeData` will not be dropped.
3. This struct is necessary in order for `add_child_and_update_its_parent`
to work. Some pointers need to be swapped between 2 nodes for this work
(and one of these pointers is a weak one). It is not possible to do this
using two `NodeData` objects, without wrapping them in `Arc`s.Implementations§
Source§impl<T> VoxelTree<T>where
T: Display,
impl<T> VoxelTree<T>where
T: Display,
pub fn new(value: T) -> VoxelTree<T>
pub fn get_copy_of_internal_arc(&self) -> NodeDataRef<T>
pub fn create_and_add_child(&self, value: T) -> NodeDataRef<T>
Sourcepub fn add_child_and_update_its_parent(&self, child: &VoxelTree<T>)
pub fn add_child_and_update_its_parent(&self, child: &VoxelTree<T>)
🔏 Write locks used.
pub fn has_parent(&self) -> bool
Sourcepub fn get_parent(&self) -> Option<NodeDataRef<T>>
pub fn get_parent(&self) -> Option<NodeDataRef<T>>
🔒 Read lock used.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for VoxelTree<T>
impl<T> RefUnwindSafe for VoxelTree<T>where
T: RefUnwindSafe,
impl<T> Send for VoxelTree<T>
impl<T> Sync for VoxelTree<T>
impl<T> Unpin for VoxelTree<T>
impl<T> UnwindSafe for VoxelTree<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more