[][src]Struct amethyst_core::Named

pub struct Named {
    pub name: Cow<'static, str>,
}

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]

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]

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]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> Event for T where
    T: Send + Sync + 'static, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Resource for T where
    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]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,