Struct Tree

Source
pub struct Tree<T> { /* private fields */ }

Implementations§

Source§

impl<T> Tree<T>

Source

pub fn cursor(&mut self, id: &NodeId) -> Option<Cursor<'_, T>>

Source

pub fn cursor_first(&mut self) -> Option<Cursor<'_, T>>

Source

pub fn cursor_last(&mut self) -> Option<Cursor<'_, T>>

Source§

impl<T> Tree<T>

Source

pub fn get(&self, id: &NodeId) -> Option<&T>

Source

pub fn get_mut(&mut self, id: &NodeId) -> Option<&mut T>

Source§

impl<T> Tree<T>

Source

pub fn iter(&self) -> Iter<'_, T>

Source

pub fn iter_from(&self, id: &NodeId) -> Iter<'_, T>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Source

pub fn into_iterator(self) -> IntoIter<T>

Source§

impl<T> Tree<T>

Source

pub fn make_child( &mut self, child: &NodeId, parent: &NodeId, ) -> Result<(), Error>

Make the child nodes as the last child of the parent node.

§Errors
  • Fails of the same NodeId is passed
  • TODO: Fail if the child node is parent of the parent node.
Source

pub fn make_prev_siblings( &mut self, node: &NodeId, sibling: &NodeId, ) -> Result<(), Error>

Make the node as the previous sibling of sibling

§Errors
  • Fails of the same NodeId is passed
  • TODO: Fail if the child node is parent of the parent node.
Source

pub fn make_next_siblings( &mut self, node: &NodeId, sibling: &NodeId, ) -> Result<(), Error>

Make the node as the next sibling of sibling

§Errors
  • Fails of the same NodeId is passed
  • TODO: Fail if the child node is parent of the parent node.
Source

pub fn detach(&mut self, node: &NodeId) -> Result<(), Error>

Detach the node from it’s parent

§Errors
  • Fails of the node was removed
Source§

impl<T> Tree<T>

Source

pub fn new() -> Self

Create a new tree.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new tree with a specific parameter.

Source

pub fn create_node(&mut self, value: T) -> NodeId

Add a node to the tree, without relations with the other nodes.

Source

pub fn remove(&mut self, id: NodeId) -> Result<T, Error>

Remove a node.

If there are some children nodes, they will became the first node if we are removing the first node. Otherwise they will become orphan nodes.

It will consume the NodeId.

§Errors

Fails if the NodeId is invalid.

Source

pub fn first_node_id(&self) -> Option<NodeId>

Source

pub fn last_node_id(&self) -> Option<NodeId>

Source

pub fn append_child(&mut self, value: T) -> NodeId

Appends the value to the last element of the three as its child. If None creates a new root.

Source

pub fn append_sibling(&mut self, value: T) -> NodeId

Appends the value to the last element of the three as its sibling. If None creates a new root.

Source

pub fn append_child_to( &mut self, id: &NodeId, value: T, ) -> Result<NodeId, Error>

Appends a new node as child of the given one

§Errors

Will error if the given node id was removed.

Source

pub fn insert_sibling_after( &mut self, id: &NodeId, value: T, ) -> Result<NodeId, Error>

Insert a new node after the as the sibling of the given one

§Errors

Will error if the given node id was removed.

Trait Implementations§

Source§

impl<T: Clone> Clone for Tree<T>

Source§

fn clone(&self) -> Tree<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Tree<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Tree<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T> IntoIterator for &'a Tree<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for Tree<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Tree<T>

§

impl<T> RefUnwindSafe for Tree<T>
where T: RefUnwindSafe,

§

impl<T> Send for Tree<T>
where T: Send,

§

impl<T> Sync for Tree<T>
where T: Sync,

§

impl<T> Unpin for Tree<T>
where T: Unpin,

§

impl<T> UnwindSafe for Tree<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.