pub struct EntityRef { /* private fields */ }
Expand description
A handle to an entity. Provides access to components.
This handle cannot be sent to another thread, as it requires
access to the main server state. To persist entity handles across
thread boundaries, you may use EntityId
instead.
Implementations§
Source§impl EntityRef
impl EntityRef
Sourcepub fn get<T: Component>(self) -> Result<ComponentRef<T>, ComponentError>
pub fn get<T: Component>(self) -> Result<ComponentRef<T>, ComponentError>
Gets a component of this entity.
Returns an error if the entity does not have this component or if the entity no longer exists.
Sourcepub fn get_mut<T: Component>(self) -> Result<ComponentRefMut<T>, ComponentError>
pub fn get_mut<T: Component>(self) -> Result<ComponentRefMut<T>, ComponentError>
Gets a mutable reference to a component of this entity.
Returns an error if the entity does not have this component or if the entity no longer exists.
Sourcepub fn add<T: Component>(self, _component: T) -> Result<(), EntityDead>
pub fn add<T: Component>(self, _component: T) -> Result<(), EntityDead>
Adds a component to this entity.
If the entity already has a component of type T
,
then the component is overwritten.
Sourcepub fn send_message(self, _message: &str) -> Result<(), ComponentError>
pub fn send_message(self, _message: &str) -> Result<(), ComponentError>
Sends a message to this entity.
Returns an error if this entity cannot receive a message. (Usually, only players and the console are capable of receiving messages.)
Sourcepub fn id(self) -> EntityId
pub fn id(self) -> EntityId
Returns the ID of this entity. This ID can be stored
for later use, usually through State::entity
.
Sourcepub fn position(self) -> Result<Position, ComponentError>
pub fn position(self) -> Result<Position, ComponentError>
Returns this entity’s Position
component.
Sourcepub fn name(self) -> Result<Name, ComponentError>
pub fn name(self) -> Result<Name, ComponentError>
Returns this entity’s Name
component.
Sourcepub fn uuid(self) -> Result<Uuid, ComponentError>
pub fn uuid(self) -> Result<Uuid, ComponentError>
Returns this entity’s Uuid
component.