Skip to main content

actions

Macro actions 

Source
macro_rules! actions {
    ($namespace:path, [ $( $(#[$attr:meta])* $name:ident),* $(,)? ]) => { ... };
    ([ $( $(#[$attr:meta])* $name:ident),* $(,)? ]) => { ... };
}
Expand description

Declares unit structs that are actions, and registers them with the app.

Each name becomes a struct that implements Action. Use this for actions that take no data. For actions with fields, use #[derive(Action)] instead.

The structs derive Clone, PartialEq, Default and Debug. Attributes written before a name, such as a doc comment, are passed on to the struct. A doc comment becomes the action’s documentation.

With a namespace, the action’s name is namespace::Name; without one, it is Name. Two actions with the same name make app creation panic.

§Examples

use gpui::{Action, actions};

actions!(editor_macro_docs, [MoveUp, MoveDown, MoveLeft, MoveRight, Newline]);

assert_eq!(MoveUp.name(), "editor_macro_docs::MoveUp");