[−][src]Struct generic_tree::Tree
A Tree represents and owns a collection of Nodes. It should be the go-to point for interacting with elements wihtin the structure.
Implementations
impl<K, V> Tree<K, V> where
K: PartialEq, [src]
K: PartialEq,
pub fn init(root: Node<K, V>) -> Self[src]
Create a new tree, given the root Node root.
pub fn get_node<Q>(&self, path: &[Q]) -> Result<&Node<K, V>, Error> where
Q: PartialEq<K>, [src]
Q: PartialEq<K>,
Get a reference to a specific Node from the tree, resolved by the list provided by path.
Errors
Returns an Err if path doesn't resolve to a Node.
Examples
let mut root = Node::new("root", 1); let child = Node::new("child", 2); root.add_child(child); let mut tree = Tree::init(root); assert!(tree.get_node(&["root"]).is_ok()); assert!(tree.get_node(&["root", "child"]).is_ok()); assert!(tree.get_node(&["boot"]).is_err()); assert!(tree.get_node(&["root", "child", "noop"]).is_err());
pub fn get_mut_node<Q>(&mut self, path: &[Q]) -> Option<&mut Node<K, V>> where
Q: PartialEq<K>, [src]
Q: PartialEq<K>,
Get a mutable reference to a specific Node from the tree, resolved by the list provided by path.
Errors
Returns an Err if path doesn't resolve to a Node.
Examples
use generic_tree::{Tree, Node}; let mut root = Node::new("root", 1); let child = Node::new("child", 2); root.add_child(child); let mut tree = Tree::init(root); let mut node = tree.get_mut_node(&["root", "child"]).unwrap(); assert_eq!(node.value(), &2); *node.mut_value() = 42;
pub fn add_node<Q>(
&mut self,
path: &[Q],
node: Node<K, V>
) -> Result<Option<Box<Node<K, V>>>, Error> where
Q: PartialEq<K>, [src]
&mut self,
path: &[Q],
node: Node<K, V>
) -> Result<Option<Box<Node<K, V>>>, Error> where
Q: PartialEq<K>,
Add a Node as a child to the Node resolved by path. If there was already a Node with the
same key, that old Node is returned.
Errors
Returns an Err if path doesn't resolve to a Node.
Examples
let mut root = Node::new("root", 1); let mut tree = Tree::init(root); let child = Node::new("child", 2); tree.add_node(&["root"], child);
pub fn remove_node<Q>(&mut self, path: &[Q]) -> Result<Box<Node<K, V>>, Error> where
Q: PartialEq<K>, [src]
Q: PartialEq<K>,
Auto Trait Implementations
impl<K, V> RefUnwindSafe for Tree<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for Tree<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Sync for Tree<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
impl<K, V> Unpin for Tree<K, V> where
K: Unpin,
V: Unpin,
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for Tree<K, V> where
K: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,