Skip to main content

tilo_actions/
key.rs

1//! Naming an action as data, and what kind of action it is.
2
3use serde::{Deserialize, Serialize};
4
5/// The stored form of a reference to one published action: a Shortcut step,
6/// an agent's plan, a palette entry, a history entry. It names the app, the
7/// resource kind that publishes the action and the action's public id.
8#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
9pub struct ActionKey {
10    pub app: String,
11    pub kind: String,
12    pub action: String,
13}
14
15/// The action id of a resource made as a whole by the platform rather than by one of the app's
16/// own actions: a package's per-workspace root, the first time a window wants it. History reads it as
17/// the resource's creation ("Created Plan").
18pub const CREATE_ACTION: &str = "$create";
19
20impl ActionKey {
21    pub fn new(app: impl Into<String>, kind: impl Into<String>, action: impl Into<String>) -> Self {
22        Self {
23            app: app.into(),
24            kind: kind.into(),
25            action: action.into(),
26        }
27    }
28}
29
30impl std::fmt::Display for ActionKey {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        write!(f, "{}/{}/{}", self.app, self.kind, self.action)
33    }
34}
35
36pub use tilo_action_policy::ActionKind;