[−][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.
Methods
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]
fn clone(&self) -> Named
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Named
[src]
impl Serialize for Named
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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 Component for Named
[src]
type Storage = DenseVecStorage<Self>
Associated storage type for this component.
Auto Trait Implementations
impl Unpin for Named
impl Sync for Named
impl Send for Named
impl UnwindSafe for Named
impl RefUnwindSafe for Named
Blanket Implementations
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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<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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> Resource for T where
T: Any + Send + Sync,
[src]
T: Any + Send + Sync,
impl<T> Event for T where
T: Send + Sync + 'static,
[src]
T: Send + Sync + 'static,
impl<T> Any for T where
T: Any,
[src]
T: Any,