[][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:

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]

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_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]

impl<'de> Deserialize<'de> for Named[src]

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]

type Owned = T

The resulting type after obtaining ownership.

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

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

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<T> Borrow<T> for T where
    T: ?Sized
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 
[src]

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

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]

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

impl<T> Any for T where
    T: Any
[src]