[−][src]Struct amethyst_core::Named
A component that gives a name to an Entity
.
There are two ways you can get a name for an entity:
- Hard-coding the entity name in code, in which case the name would be a
&'static str
. - Dynamically generating the string or loading it from a data file, in which case the name
would be a
String
.
To support both of these cases smoothly, Named
stores the name as Cow<'static, str>
.
You can pass either a &'static str
or a String
to Named::new
, and your code
can generally treat the name
field as a &str
without needing to know whether the
name is actually an owned or borrowed string.
Examples
Creating a name from string constant:
use amethyst::core::{Named, WithNamed}; use amethyst::ecs::prelude::*; let mut world = World::new(); world.register::<Named>(); world .create_entity() .named("Super Cool Entity") .build();
Creating a name from a dynamically generated string:
use amethyst::core::{Named, WithNamed}; use amethyst::ecs::prelude::*; let mut world = World::new(); world.register::<Named>(); for entity_num in 0..10 { world .create_entity() .named(format!("Entity Number {}", entity_num)) .build(); }
Accessing a named entity in a system:
use amethyst::core::Named; use amethyst::ecs::prelude::*; pub struct NameSystem; impl<'s> System<'s> for NameSystem { type SystemData = ( Entities<'s>, ReadStorage<'s, Named>, ); fn run(&mut self, (entities, names): Self::SystemData) { for (entity, name) in (&*entities, &names).join() { println!("Entity {:?} is named {}", entity, name.name); } } }
Fields
name: Cow<'static, str>
The name of the entity this component is attached to.
Implementations
impl Named
[src]
pub fn new<S>(name: S) -> Self where
S: Into<Cow<'static, str>>,
[src]
S: Into<Cow<'static, str>>,
Constructs a new Named
from a string.
Examples
From a string constant:
use amethyst::core::Named; let name_component = Named::new("Super Cool Entity");
From a dynamic string:
use amethyst::core::Named; let entity_num = 7; let name_component = Named::new(format!("Entity Number {}", entity_num));
Trait Implementations
impl Clone for Named
[src]
impl Component for Named
[src]
type Storage = DenseVecStorage<Self>
Associated storage type for this component.
impl Debug for Named
[src]
impl<'de> Deserialize<'de> for Named
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Serialize for Named
[src]
Auto Trait Implementations
impl RefUnwindSafe for Named
impl Send for Named
impl Sync for Named
impl Unpin for Named
impl UnwindSafe for Named
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Any for T where
T: Any,
T: Any,
fn get_type_id(&self) -> TypeId
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> Event for T where
T: Send + Sync + 'static,
T: Send + Sync + 'static,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Resource for T where
T: Any + Send + Sync,
T: Any + Send + Sync,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
[src]
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
[src]
fn is_in_subset(&self) -> bool
[src]
unsafe fn to_subset_unchecked(&self) -> SS
[src]
fn from_subset(element: &SS) -> SP
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,