entity

Attribute Macro entity 

Source
#[entity]
Expand description

Implements the HasName trait for an entity struct.

This macro provides flexible name resolution for entities. The StateEntity trait is automatically implemented by the #[stately::state] macro when the entity is added to a state struct.

§Attributes

  • #[stately::entity] - Uses the default “name” field
  • #[stately::entity(name_field = "field_name")] - Uses a different field for the name
  • #[stately::entity(name_method = "method_name")] - Calls a method to get the name
  • #[stately::entity(singleton)] - For singleton entities, returns “default” as the name

§Examples

// Default: uses the "name" field
#[stately::entity]
pub struct Pipeline {
    pub name: String,
    pub source: Link<SourceConfig>,
}

// Custom field name
#[stately::entity(name_field = "identifier")]
pub struct Config {
    identifier: String,
}

// Custom method
#[stately::entity(name_method = "get_name")]
pub struct Task {
    id: String,
}
impl Task {
    fn get_name(&self) -> &str { &self.id }
}