Action

Derive Macro Action 

Source
#[derive(Action)]
{
    // Attributes available to this derive:
    #[action]
}
Expand description

Derive macro for the Action trait

Generates a name() method that returns the variant name as a static string.

With #[action(infer_categories)], also generates:

  • category() -> Option<&'static str> - Get action’s category
  • category_enum() -> {Name}Category - Get category as enum
  • is_{category}() predicates for each category
  • {Name}Category enum with all discovered categories

With #[action(generate_dispatcher)], also generates:

  • {Name}Dispatcher trait with category-based dispatch methods

§Example

#[derive(Action, Clone, Debug)]
#[action(infer_categories, generate_dispatcher)]
enum MyAction {
    SearchStart,
    SearchClear,
    ConnectionFormOpen,
    ConnectionFormSubmit,
    DidConnect,
    Tick,  // uncategorized
}

let action = MyAction::SearchStart;
assert_eq!(action.name(), "SearchStart");
assert_eq!(action.category(), Some("search"));
assert!(action.is_search());