pub struct Tree<T: Clone> { /* private fields */ }
Expand description
A persistent, indexable, hierarchical data structure
See the module docs for more information
Implementations§
Source§impl<T: Clone> Tree<T>
impl<T: Clone> Tree<T>
Sourcepub fn new_with_root(value: T) -> Self
pub fn new_with_root(value: T) -> Self
Create a new Tree with the specified root
Sourcepub fn insert(
&mut self,
value: T,
location: Location,
) -> Result<NodeId, InvalidLocation>
pub fn insert( &mut self, value: T, location: Location, ) -> Result<NodeId, InvalidLocation>
Insert a new node at the specified location
Error if the location is invalid:
- The root node cannot have siblings
- The location must reference only existing nodes
Sourcepub fn root(&self) -> NodeRef<'_, T>
pub fn root(&self) -> NodeRef<'_, T>
Get a reference to the root node
The tree will always have a root node
Sourcepub fn root_mut(&mut self) -> NodeMut<'_, T>
pub fn root_mut(&mut self) -> NodeMut<'_, T>
Get a mutable reference to the root node
The tree will always have a root node
Sourcepub fn get(&self, id: NodeId) -> Option<NodeRef<'_, T>>
pub fn get(&self, id: NodeId) -> Option<NodeRef<'_, T>>
Get a reference to the node with the specified ID
If there is no such node, returns None
Sourcepub fn get_mut(&mut self, id: NodeId) -> Option<NodeMut<'_, T>>
pub fn get_mut(&mut self, id: NodeId) -> Option<NodeMut<'_, T>>
Get a mutable reference to the node with the specified ID
If there is no such node, returns None
Sourcepub fn iter_nodes(&self) -> impl Iterator<Item = NodeRef<'_, T>>
pub fn iter_nodes(&self) -> impl Iterator<Item = NodeRef<'_, T>>
Iterate over all nodes in the Tree, in unspecified order
Trait Implementations§
impl<T: Clone> StructuralPartialEq for Tree<T>
Auto Trait Implementations§
impl<T> Freeze for Tree<T>
impl<T> RefUnwindSafe for Tree<T>where
T: RefUnwindSafe,
impl<T> Send for Tree<T>
impl<T> Sync for Tree<T>
impl<T> Unpin for Tree<T>where
T: Unpin,
impl<T> UnwindSafe for Tree<T>where
T: UnwindSafe + 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