Struct NodeBuilder

Source
pub struct NodeBuilder<T> { /* private fields */ }
Expand description

A Node builder that provides more control over how a Node is created.

Implementations§

Source§

impl<T> NodeBuilder<T>

Source

pub fn new(data: T) -> NodeBuilder<T>

Creates a new NodeBuilder with the required data.

use id_tree::NodeBuilder;

let _node_builder = NodeBuilder::new(5);
Source

pub fn with_child_capacity(self, child_capacity: usize) -> NodeBuilder<T>

Set the child capacity of the NodeBuilder.

As Nodes are added to a Tree, parent and child references must be maintained. To do this, an allocation must be made every time a child is added to a Node. Using this setting allows the Node to pre-allocate space for its children so that the allocations aren’t made as children are added.

Use of this setting is recommended if you know the maximum number of children (not including grandchildren, great-grandchildren, etc.) that a Node will have at any given time.

use id_tree::NodeBuilder;

let _node_builder = NodeBuilder::new(5).with_child_capacity(3);
Source

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

Build a Node based upon the current settings in the NodeBuilder.

use id_tree::NodeBuilder;
use id_tree::Node;

let node: Node<i32> = NodeBuilder::new(5)
        .with_child_capacity(3)
        .build();

assert_eq!(node.data(), &5);
assert_eq!(node.children().capacity(), 3);

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.