pub struct NodeBuilder<T> {
pub content: T,
pub children: Vec<Self>,
}
Expand description
Helper struct to build a Tree
of Node
s.
§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>
impl<T> NodeBuilder<T>
Trait Implementations§
Source§impl<T: Debug> Debug for NodeBuilder<T>
impl<T: Debug> Debug for NodeBuilder<T>
Source§impl<T: Default> Default for NodeBuilder<T>
impl<T: Default> Default for NodeBuilder<T>
Source§fn default() -> NodeBuilder<T>
fn default() -> NodeBuilder<T>
Returns the “default value” for a type. Read more
Source§impl<T> From<NodeBuilder<T>> for Tree<T>
impl<T> From<NodeBuilder<T>> for Tree<T>
Source§fn from(builder: NodeBuilder<T>) -> Self
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more