Struct CursorMut

Source
pub struct CursorMut<'a, T> { /* private fields */ }
Expand description

A cursor over mutable Node data with safe, reference-counted Position handles.

This struct represents the majority of major operations for the GenTree structure. All operations run in O(1) time unless otherwise noted.

Implementations§

Source§

impl<'a, T> CursorMut<'a, T>

Source

pub fn is_root(&self) -> bool

Returns true if the Node under the curosr is the tree’s root

Source

pub fn is_some(&self) -> bool

Returns true if the Node under the curosr has data

Source

pub fn is_none(&self) -> bool

Returns true if the Node under the cursor is empty

Source

pub fn num_children(&self) -> usize

Returns the number of children for the Node under the cursor as usize

Source

pub fn depth(&self) -> usize

Returns the depth of the cursor from the tree’s root

Source

pub fn height(&self) -> usize

Returns the height of the tallest sub-tree for the current position ** The recursive guts of the height function */

Source

pub fn get_data(&self) -> Option<Ref<'_, T>>

Returns an immutable reference to the data under the cursor, if Some

Source

pub fn get_for_pos(&'a self, pos: &'a Position<T>) -> Option<Ref<'a, T>>

Returns an immutable reference to the data for a supplied Position

Source

pub fn add_child(&mut self, data: T)

Adds a new child Node under the current cursor and advances the cursor to the new child

Source

pub fn children(&self) -> Vec<Position<T>>

Returns a list of owned descendant (child) Positions for the Node under the cursor in O(c) time where c is the number of children; The clone used here is a cheap pointer copy, not an underlying data copy

Source

pub fn delete(&mut self) -> Option<T>

Warning: Broken! Does not handle root deletion properly.

Removes the node at the current cursor position and returns its data, if Some. Operation executes in O(c) time where c is the number of children for the given node; Adds all children to the parent (if Some), and returns the deleted Node; If the cursor is at the tree’s root, this just deletes the Node’s data, leaving None; Moves the cursor to the parent, if Some */

Source

pub fn current(&self) -> &Position<T>

Returns a reference to the current Position

Source

pub fn jump(&mut self, new: &Position<T>)

Jump the cursor to the given Position

Source

pub fn ascend(&mut self) -> Result<(), String>

Moves the cursor up a generation, if Some; Trying to ascend past the root results in an error

Auto Trait Implementations§

§

impl<'a, T> Freeze for CursorMut<'a, T>

§

impl<'a, T> !RefUnwindSafe for CursorMut<'a, T>

§

impl<'a, T> !Send for CursorMut<'a, T>

§

impl<'a, T> !Sync for CursorMut<'a, T>

§

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

§

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

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> 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, 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V