Skip to main content

Tree

Struct Tree 

Source
pub struct Tree { /* private fields */ }
Expand description

The arena holding one document’s nodes, with the document at Tree::root.

Implementations§

Source§

impl Tree

Source

pub fn new(root_type: NodeType) -> Self

A tree holding only a fresh node of root_type, which becomes the root.

Source

pub fn root(&self) -> NodeId

The root node’s id (the document, for a parse).

Source

pub fn add(&mut self, node: MdNode) -> NodeId

Add an unlinked node to the arena and return its id: a slot Tree::free_subtree gave back, when there is one.

Source

pub fn free_subtree(&mut self, node: NodeId) -> Vec<NodeId>

Detach node and give its slot, and the slots of every node below it, back to the arena for Tree::add to fill, dropping what each held; answer the ids given back. Only for a node nothing will read again: a slot given back takes the next node added, under the same id. Iterative, since nesting is the input’s to choose.

Source

pub fn new_node(&mut self, node_type: NodeType) -> NodeId

Add an open, unlinked node of node_type.

Source

pub fn get(&self, id: NodeId) -> &MdNode

Source

pub fn get_mut(&mut self, id: NodeId) -> &mut MdNode

Source

pub fn len(&self) -> usize

How many slots the arena holds, unlinked nodes’ and given-back ones included.

Source

pub fn is_empty(&self) -> bool

Source

pub fn children(&self, parent: NodeId) -> Vec<NodeId>

The children of parent, first to last.

Source

pub fn append_child(&mut self, parent: NodeId, child: NodeId)

Add child as the last child of parent, detaching it first.

Source

pub fn prepend_child(&mut self, parent: NodeId, child: NodeId)

Add child as the first child of parent, detaching it first.

Source

pub fn insert_after(&mut self, node: NodeId, sibling: NodeId)

Place sibling directly after node.

Source

pub fn insert_before(&mut self, node: NodeId, sibling: NodeId)

Place sibling directly before node.

Detach node from the tree, leaving the node itself intact.

Source

pub fn walker(&self, root: NodeId) -> Walker

A depth-first walker rooted at root. Containers are entered and exited; leaves produce one event.

Trait Implementations§

Source§

impl Clone for Tree

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Tree

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Tree

§

impl Freeze for Tree

§

impl RefUnwindSafe for Tree

§

impl Send for Tree

§

impl Sync for Tree

§

impl Unpin for Tree

§

impl UnsafeUnpin for Tree

§

impl UnwindSafe for Tree

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.