[][src]Struct slab_tree::NodeMut

pub struct NodeMut<'a, T> { /* fields omitted */ }

A mutable reference to a given Node's data and its relatives.

Methods

impl<'a, T> NodeMut<'a, T>[src]

pub fn node_id(&self) -> NodeId[src]

Returns the NodeId that identifies this Node in the tree.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let root_id = tree.root_id().expect("root doesn't exist?");
let root = tree.root_mut().expect("root doesn't exist?");

let root_id_again = root.node_id();

assert_eq!(root_id_again, root_id);

pub fn data(&mut self) -> &mut T[src]

Returns a mutable reference to the data contained by the given Node.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");

let data = root.data();

assert_eq!(data, &mut 1);

*data = 3;

assert_eq!(data, &mut 3);

pub fn parent(&mut self) -> Option<NodeMut<T>>[src]

Returns a NodeMut pointing to this Node's parent. Returns a Some-value containing the NodeMut if this Node has a parent; otherwise returns a None.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");

assert!(root.parent().is_none());

pub fn prev_sibling(&mut self) -> Option<NodeMut<T>>[src]

Returns a NodeMut pointing to this Node's previous sibling. Returns a Some-value containing the NodeMut if this Node has a previous sibling; otherwise returns a None.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");

assert!(root.prev_sibling().is_none());

pub fn next_sibling(&mut self) -> Option<NodeMut<T>>[src]

Returns a NodeMut pointing to this Node's next sibling. Returns a Some-value containing the NodeMut if this Node has a next sibling; otherwise returns a None.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");

assert!(root.next_sibling().is_none());

pub fn first_child(&mut self) -> Option<NodeMut<T>>[src]

Returns a NodeMut pointing to this Node's first child. Returns a Some-value containing the NodeMut if this Node has a first child; otherwise returns a None.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");

assert!(root.first_child().is_none());

pub fn last_child(&mut self) -> Option<NodeMut<T>>[src]

Returns a NodeMut pointing to this Node's last child. Returns a Some-value containing the NodeMut if this Node has a last child; otherwise returns a None.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");

assert!(root.last_child().is_none());

pub fn append(&mut self, data: T) -> NodeMut<T>[src]

Appends a new Node as this Node's last child (and first child if it has none). Returns a NodeMut pointing to the newly added Node.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");

root.append(2);

assert!(root.first_child().is_some());
assert_eq!(root.first_child().unwrap().data(), &mut 2);

assert!(root.last_child().is_some());
assert_eq!(root.last_child().unwrap().data(), &mut 2);

let mut child = root.first_child().unwrap();

assert!(child.parent().is_some());
assert_eq!(child.parent().unwrap().data(), &mut 1);

pub fn prepend(&mut self, data: T) -> NodeMut<T>[src]

Prepends a new Node as this Node's first child (and last child if it has none). Returns a NodeMut pointing to the newly added Node.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");

root.prepend(2);

assert!(root.first_child().is_some());
assert_eq!(root.first_child().unwrap().data(), &mut 2);

assert!(root.last_child().is_some());
assert_eq!(root.last_child().unwrap().data(), &mut 2);

let mut child = root.first_child().unwrap();

assert!(child.parent().is_some());
assert_eq!(child.parent().unwrap().data(), &mut 1);

pub fn remove_first(&mut self, behavior: RemoveBehavior) -> Option<T>[src]

Remove the first child of this Node and return the data that child contained. Returns a Some-value if this Node has a child to remove; returns a None-value otherwise.

Children of the removed Node can either be dropped with DropChildren or orphaned with OrphanChildren.

use slab_tree::tree::TreeBuilder;
use slab_tree::behaviors::RemoveBehavior::*;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");
root.append(2);
root.append(3);

let two = root.remove_first(DropChildren);

assert!(two.is_some());
assert_eq!(two.unwrap(), 2);

assert!(root.first_child().is_some());
assert_eq!(root.first_child().unwrap().data(), &mut 3);

assert!(root.last_child().is_some());
assert_eq!(root.last_child().unwrap().data(), &mut 3);

pub fn remove_last(&mut self, behavior: RemoveBehavior) -> Option<T>[src]

Remove the first child of this Node and return the data that child contained. Returns a Some-value if this Node has a child to remove; returns a None-value otherwise.

Children of the removed Node can either be dropped with DropChildren or orphaned with OrphanChildren.

use slab_tree::tree::TreeBuilder;
use slab_tree::behaviors::RemoveBehavior::*;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");
root.append(2);
root.append(3);

let three = root.remove_last(DropChildren);

assert!(three.is_some());
assert_eq!(three.unwrap(), 3);

assert!(root.first_child().is_some());
assert_eq!(root.first_child().unwrap().data(), &mut 2);

assert!(root.last_child().is_some());
assert_eq!(root.last_child().unwrap().data(), &mut 2);

pub fn as_ref(&self) -> NodeRef<T>[src]

Returns a NodeRef pointing to this NodeMut.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let mut root = tree.root_mut().expect("root doesn't exist?");
root.append(2);

let root = root.as_ref();

assert_eq!(root.data(), &1);

pub fn swap_next_sibling(&mut self) -> bool[src]

Exchange positions with the next sibling.

Returns true if swapped with a next sibling, returns false if this was already the last sibling.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let two_id = {
    let mut root = tree.root_mut().expect("root doesn't exist?");
    let two_id = root.append(2).node_id();
    root.append(3);
    root.append(4);
    two_id
};
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![2, 3, 4]);
assert!(tree.get_mut(two_id).unwrap().swap_next_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![3, 2, 4]);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    3);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    4);
assert!(tree.get_mut(two_id).unwrap().swap_next_sibling());
assert_eq!(
  tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![3, 4, 2]);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    3);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    2);
assert!(!tree.get_mut(two_id).unwrap().swap_next_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![3, 4, 2]);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    3);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    2);

pub fn swap_prev_sibling(&mut self) -> bool[src]

Exchange positions with the previous sibling.

Returns true if swapped with a previous sibling, returns false if this was already the first sibling.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let four_id = {
    let mut root = tree.root_mut().expect("root doesn't exist?");
    root.append(2);
    root.append(3);
    let four_id = root.append(4).node_id();
    four_id
};
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![2, 3, 4]);
assert!(tree.get_mut(four_id).unwrap().swap_prev_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![2, 4, 3]);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    2);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    3);
assert!(tree.get_mut(four_id).unwrap().swap_prev_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![4, 2, 3]);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    4);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    3);
assert!(!tree.get_mut(four_id).unwrap().swap_prev_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![4, 2, 3]);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    4);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    3);

pub fn make_last_sibling(&mut self) -> bool[src]

Moves this node to the last sibling position.

Returns false if the node was already the last sibling.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let two_id = {
    let mut root = tree.root_mut().expect("root doesn't exist?");
    let two_id = root.append(2).node_id();
    root.append(3);
    root.append(4);
    two_id
};
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![2, 3, 4]);
assert!(tree.get_mut(two_id).unwrap().make_last_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![3, 4, 2]);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    3);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    2);
assert!(!tree.get_mut(two_id).unwrap().make_last_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![3, 4, 2]);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    3);
assert_eq!(
    *tree.get(two_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    2);

pub fn make_first_sibling(&mut self) -> bool[src]

Moves this node to the first sibling position.

Returns false if the node was already the first sibling.

use slab_tree::tree::TreeBuilder;

let mut tree = TreeBuilder::new().with_root(1).build();
let four_id = {
    let mut root = tree.root_mut().expect("root doesn't exist?");
    root.append(2);
    root.append(3);
    root.append(4).node_id()
};
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![2, 3, 4]);
assert!(tree.get_mut(four_id).unwrap().make_first_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![4, 2, 3]);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    4);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    3);
assert!(!tree.get_mut(four_id).unwrap().make_first_sibling());
assert_eq!(
    tree.root().unwrap().children().map(|child_ref| *child_ref.data())
        .collect::<Vec<i32>>(),
    vec![4, 2, 3]);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().first_child().unwrap()
        .data(),
    4);
assert_eq!(
    *tree.get(four_id).unwrap().parent().unwrap().last_child().unwrap()
        .data(),
    3);

Trait Implementations

impl<'a, T: Debug> Debug for NodeMut<'a, T>[src]

impl<'a, T: PartialEq> PartialEq<NodeMut<'a, T>> for NodeMut<'a, T>[src]

impl<'a, T> StructuralPartialEq for NodeMut<'a, T>[src]

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for NodeMut<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for NodeMut<'a, T> where
    T: Send

impl<'a, T> Sync for NodeMut<'a, T> where
    T: Sync

impl<'a, T> Unpin for NodeMut<'a, T>

impl<'a, T> !UnwindSafe for NodeMut<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.