Skip to main content

Tree

Struct Tree 

Source
pub struct Tree {
    pub label: Option<Box<dyn Content>>,
    pub content: Box<dyn Content>,
    pub subtrees: Vec<Tree>,
}
Expand description

A tree node containing content and child subtrees.

Trees are built from a root node with zero or more child nodes, each of which can have their own children. Nodes can optionally have labels that appear alongside their content.

§Example

use tree_display::{Tree, format::Member};

let tree = Tree::leaf("root")
    .labeled(Member::new("label"));

Fields§

§label: Option<Box<dyn Content>>

Optional label displayed next to the content

§content: Box<dyn Content>

The main content of this node

§subtrees: Vec<Tree>

Child subtrees

Implementations§

Source§

impl Tree

Source

pub fn new(content: impl Content, subtrees: Vec<Tree>) -> Tree

Creates a new tree node with content and children.

Source

pub fn leaf(content: impl Content) -> Tree

Creates a leaf node (a node with no children).

Source

pub fn labeled(self, label: impl Content) -> Self

Adds a label to the node.

Labels appear before the content, typically as a key or name.

Source

pub fn is_leaf(&self) -> bool

Returns whether this node is a leaf (has no children).

Auto Trait Implementations§

§

impl !RefUnwindSafe for Tree

§

impl !Send for Tree

§

impl !Sync for Tree

§

impl !UnwindSafe for Tree

§

impl Freeze for Tree

§

impl Unpin for Tree

§

impl UnsafeUnpin 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> 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<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T, S> SpanWrap<S> for T
where S: WrappingSpan<T>,

Source§

fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned

Invokes WrappingSpan::make_wrapped to wrap an AST node in a span.
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.