pub struct EntityWorldMut<'w> { /* private fields */ }Expand description
A mutable reference to an entity’s data within a World.
EntityWorldMut provides a fluent builder API for constructing entities
with components. It holds a mutable borrow of the world, allowing chained
component insertions.
§Builder Pattern
The primary use is via World::spawn() for fluent entity construction:
let entity = world.spawn()
.insert(Position { x: 0.0, y: 0.0 })
.insert(Velocity { x: 1.0, y: 0.0 })
.id();§Lifetime
The builder holds a mutable borrow of the World, so you cannot access
the world while an EntityWorldMut exists. Call id() to
get the entity ID and release the borrow.
§Thread Safety
EntityWorldMut is not Send or Sync - it’s designed for single-threaded
entity construction. For batch spawning, use World::spawn_batch() (future).
Implementations§
Source§impl<'w> EntityWorldMut<'w>
impl<'w> EntityWorldMut<'w>
Sourcepub fn world(&self) -> &World
pub fn world(&self) -> &World
Returns a reference to the World containing this entity.
This allows read-only access to world state while building an entity.
For mutable access, you’ll need to finish building and drop this
EntityWorldMut first.
Sourcepub fn insert<T: Component>(&mut self, component: T) -> &mut Self
pub fn insert<T: Component>(&mut self, component: T) -> &mut Self
Inserts a component on this entity.
If the entity already has a component of this type, it is replaced.
Returns self for method chaining.
§Type Parameters
T: The component type to insert
§Arguments
component- The component value to insert
§Returns
&mut Self for fluent method chaining.
§Example
use goud_engine::ecs::{World, Component};
#[derive(Debug, Clone, Copy, PartialEq)]
struct Position { x: f32, y: f32 }
impl Component for Position {}
#[derive(Debug, Clone, Copy, PartialEq)]
struct Velocity { x: f32, y: f32 }
impl Component for Velocity {}
let mut world = World::new();
// Fluent builder pattern
let entity = world.spawn()
.insert(Position { x: 0.0, y: 0.0 })
.insert(Velocity { x: 1.0, y: 0.0 })
.id();
assert!(world.has::<Position>(entity));
assert!(world.has::<Velocity>(entity));
assert_eq!(world.get::<Position>(entity), Some(&Position { x: 0.0, y: 0.0 }));
assert_eq!(world.get::<Velocity>(entity), Some(&Velocity { x: 1.0, y: 0.0 }));§Archetype Transitions
Each insert call may trigger an archetype transition if the entity
doesn’t already have the component type. Multiple inserts in sequence
will create intermediate archetypes.
Trait Implementations§
Auto Trait Implementations§
impl<'w> Freeze for EntityWorldMut<'w>
impl<'w> !RefUnwindSafe for EntityWorldMut<'w>
impl<'w> !Send for EntityWorldMut<'w>
impl<'w> !Sync for EntityWorldMut<'w>
impl<'w> Unpin for EntityWorldMut<'w>
impl<'w> UnsafeUnpin for EntityWorldMut<'w>
impl<'w> !UnwindSafe for EntityWorldMut<'w>
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
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more