Struct NodeBuilder

Source
pub struct NodeBuilder<T> {
    pub content: T,
    pub children: Vec<Self>,
}
Expand description

Helper struct to build a Tree of Nodes.

§Examples

Can be used as a Builder Pattern, or something similar, but by assigning the fields.

let tree1 = Node::builder("parent")
    .child(Node::builder("child a"))
    .child(Node::builder("child b")
        .child(Node::builder("child c")))
    .build();

// Or:

let tree2 = NodeBuilder {
    content: "parent",
    children: vec![
        NodeBuilder {
            content: "child a",
            children: vec![]
        },
        NodeBuilder {
            content: "child b",
            children: vec![
                NodeBuilder {
                    content: "child c",
                    children: vec![]
                }
            ]
        },
    ],
}.build();

assert_eq!(tree1, tree2);

Fields§

§content: T§children: Vec<Self>

Implementations§

Source§

impl<T> NodeBuilder<T>

Source

pub fn new(content: T) -> Self

Source

pub fn child(self, child: Self) -> Self

Source

pub fn build(self) -> Tree<T>

Create a new Tree from nodes with children and content. The children will be made into Pinned Nodes with the proper parent.

Trait Implementations§

Source§

impl<T: Debug> Debug for NodeBuilder<T>

Source§

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

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

impl<T: Default> Default for NodeBuilder<T>

Source§

fn default() -> NodeBuilder<T>

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

impl<T> From<NodeBuilder<T>> for Tree<T>

Source§

fn from(builder: NodeBuilder<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for NodeBuilder<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

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