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

Ergonomically construct trees without knowledge of world.

This struct builds the world using EntityBuilder

Example

use hecs_hierarchy::*;
use hecs::*;

struct Tree;
let mut world = World::default();
let mut builder = TreeBuilder::<Tree>::from(("root",));
builder.attach(("child 1",));
builder.attach({
    let mut builder = TreeBuilder::new();
    builder.add("child 2");
    builder
});
let root = builder.spawn(&mut world);
assert_eq!(*world.get::<&'static str>(root).unwrap(), "root");
for (a, b) in world
    .descendants_depth_first::<Tree>(root)
    .zip(["child 1", "child 2"])
{
    assert_eq!(*world.get::<&str>(a).unwrap(), b)
}

Implementations

Construct a new empty tree

Reserve the entity which this node will spawn

Spawn the whole tree into the world

Spawn the whole tree into a commandbuffer. The world is required for reserving entities.

Add a component to the root

Add a bundle to the root

Atttach a new subtree

Attach a new leaf as a bundle

Consuming variant of Self::attach.

This is useful for nesting to alleviate the need to save an intermediate builder

Consuming variant of Self::attach_tree. This is useful for nesting to alleviate the need to save an intermediate builder

Get a reference to the deferred tree builder’s children.

Get a reference to the deferred tree builder’s root.

Get a mutable reference to the deferred tree builder’s root.

Trait Implementations

Performs the conversion.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.