diff options
Diffstat (limited to 'engine-ecs/src/entity.rs')
| -rw-r--r-- | engine-ecs/src/entity.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/engine-ecs/src/entity.rs b/engine-ecs/src/entity.rs index d7b63be..9ef9da0 100644 --- a/engine-ecs/src/entity.rs +++ b/engine-ecs/src/entity.rs @@ -1,14 +1,15 @@ use std::any::{type_name, Any}; +use std::borrow::Cow; use std::ops::Deref; use std::sync::LazyLock; +use crate::Component; use crate::component::storage::archetype::{ Archetype, Entity as ArchetypeEntity, MatchingComponentIter as ArchetypeMatchingComponentIter, }; use crate::component::{ - Component, Handle as ComponentHandle, HandleMut as ComponentHandleMut, }; @@ -42,6 +43,18 @@ impl<'a> Handle<'a> self.entity.uid() } + /// Returns a reference to the [`Name`] component in this entity. `None` is + /// returned if the component isn't found in the entity. + /// + /// # Panics + /// Will panic if: + /// - The component is mutably borrowed elsewhere + #[must_use] + pub fn get_name(&self) -> Option<ComponentHandle<'a, Name>> + { + self.get::<Name>() + } + /// Returns a reference to the specified component in this entity. `None` is /// returned if the component isn't found in the entity. /// @@ -315,3 +328,10 @@ macro_rules! declare_entity { }); } } + +/// Entity name. +#[derive(Debug, Clone, Component)] +pub struct Name +{ + pub name: Cow<'static, str> +} |
