Skip to main content

examples/reflection/
entity_type.rs

1use crate::z_ignore_test_common::*;
2
3use flecs_ecs::prelude::*;
4
5#[derive(Component)]
6#[flecs(meta)]
7pub struct TypeWithEntity {
8    pub e: Entity,
9}
10
11fn main() {
12    let mut world = World::new();
13
14    /* Alternatively, you can do it manually like so (without the derive macro)
15    .member(Entity::id(),"e", 1, core::mem::offset_of!(TypeWithEntity, e));
16    */
17
18    let bar = world.entity_named("bar");
19
20    // Create a new entity with the TypeWithEntity component
21    let e = world.entity().set(TypeWithEntity { e: bar.into() });
22
23    // Convert TypeWithEntity component to flecs expression string
24    e.get::<&TypeWithEntity>(|p| {
25        let expr: String = world.to_expr(p);
26        println!("TypeWithEntity: {expr}");
27    });
28
29    // Output:
30    //  TypeWithEntity: {e: foo}
31}