Skip to main content

WorldExt

Trait WorldExt 

Source
pub trait WorldExt {
    // Required methods
    fn bind_entity(&self, entity: Entity) -> BoundEntity<'_>;
    fn entity_ptr(&self, entity: Entity) -> EntityPtr;
}
Expand description

Extension trait for World providing ergonomic entity access methods.

This trait adds convenience methods to World that hide the internal unsafe boundary, making entity access more ergonomic.

§Example

use bevy_ecs::prelude::*;
use bevy_entity_ptr::WorldExt;

#[derive(Component)]
struct Health(i32);

fn my_system(world: &World, entity: Entity) {
    // No unsafe needed!
    let ptr = world.entity_ptr(entity);
    if let Some(health) = ptr.get::<Health>() {
        println!("Health: {}", health.0);
    }
}

Required Methods§

Source

fn bind_entity(&self, entity: Entity) -> BoundEntity<'_>

Creates a BoundEntity for scoped access with explicit lifetime.

This is the safest approach with compiler-checked lifetimes. Use when you want explicit lifetime tracking.

Source

fn entity_ptr(&self, entity: Entity) -> EntityPtr

Creates an EntityPtr for ergonomic traversal.

This hides the internal unsafe, providing a clean API for complex entity graph traversal. The EntityPtr is !Send, preventing escape to other threads.

§Safety Guarantee

Within a Bevy system, &World outlives the system scope. Since EntityPtr is !Send, it cannot escape the system.

Implementations on Foreign Types§

Source§

impl WorldExt for World

Source§

fn bind_entity(&self, entity: Entity) -> BoundEntity<'_>

Source§

fn entity_ptr(&self, entity: Entity) -> EntityPtr

Implementors§