Struct Node

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

Implementations§

Source§

impl<T> Node<T>
where T: Eq + Hash,

Source

pub fn new_leaf(text: String) -> Node<T>

Create new leaf node.

Source

pub fn new() -> Node<T>

Create new node.

Source

pub fn new_root(string: &str) -> Node<T>

Create new root node.

Source

pub fn id(&self) -> &String

Get the ID of the node.

Source

pub fn is_leaf(&self) -> bool

Check whether this node is a

Source

pub fn add_child(&mut self, child: Node<T>)

Add a child to this node.

Source

pub fn text(&self) -> String

Get text the node (or children) is/are holding.

Source

pub fn length(&self) -> usize

Length of the underlying text.

Source

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

Get iterator over all infos this node has.

Source

pub fn add_info(&mut self, info: Rc<T>)

Add info to the node.

Source

pub fn clear_infos(&mut self)

Clear all infos from this node without recursion in children.

Source

pub fn remove_info( &mut self, start_idx: usize, end_idx: usize, info: Rc<T>, recurse: bool, ) -> Option<Vec<Node<T>>>

Remove info from the node. Specify recurse whether the info should be removed from children as well. Since a node can end up useless without info, it might have to be replaced by its children which are then returned by this method.

Source

pub fn has_info(&self, info: &T) -> bool

Check if the node has the passed info.

Source

pub fn set( &mut self, start_idx: usize, end_idx: usize, info: Rc<T>, ) -> Option<Vec<Node<T>>>

Set syntax/format info for the passed range. The range is the passed start index (inclusive) to the passed end index (exclusive). Returns a list of nodes to replace the current one in case that is needed (optional).

Source

pub fn unset(&mut self, start_idx: usize, end_idx: usize, info: Rc<T>)

Unset the passed syntax/format info for the passed range. The range is the passed start index (inclusive) to the passed end index (exclusive).

Source

pub fn insert(&mut self, idx: usize, ch: char)

Insert a char in the underlying text.

Source

pub fn insert_str(&mut self, idx: usize, string: &str)

Insert a string in the underlying text.

Source

pub fn push(&mut self, ch: char)

Push a char to the underlying text.

Source

pub fn push_str(&mut self, string: &str)

Push a string to the underlying text.

Source

pub fn child_count(&self) -> usize

Get the count of children under this node.

Source

pub fn remove(&mut self, idx: usize, count: usize) -> (bool, bool)

Remove a count of characters from the underlying text starting at idx. Removing a character might lead to having an empty leaf left. Method will return boolean tuple with two elements (bool, bool). The first boolean will determine whether the node is unnecessary now, the second boolean determined whether parent may need to regroup its children.

Source

pub fn children(&self) -> &[Node<T>]

Get a slice of all children under this node.

Source

pub fn give_listener(&mut self, l: &Option<Rc<Listener<T>>>)

Give node change listener.

Source

pub fn take_listener(&mut self) -> Option<Rc<Listener<T>>>

Take the change listener from this node (if any).

Source

pub fn pre_order_iter(&self) -> PreOrder<'_, T>

Get a depth first pre order iterator.

Source

pub fn leaf_iter(&self) -> impl Iterator<Item = Item<'_, T>>

Get a leaf iterator.

Trait Implementations§

Source§

impl<T> Debug for Node<T>
where T: Ord + Hash + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Node<T>

§

impl<T> !RefUnwindSafe for Node<T>

§

impl<T> !Send for Node<T>

§

impl<T> !Sync for Node<T>

§

impl<T> Unpin for Node<T>

§

impl<T> !UnwindSafe for Node<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.