fret_runtime/command.rs
1use std::sync::Arc;
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
4/// Stable command identifier.
5///
6/// Command ids are used to register commands, route input, and bind key chords across the
7/// workspace. They are expected to be stable and human-readable (e.g. `"app.quit"`,
8/// `"workspace.toggle_sidebar"`).
9pub struct CommandId(pub Arc<str>);
10
11impl CommandId {
12 /// Creates a new command id from an owned or shared string.
13 pub fn new(id: impl Into<Arc<str>>) -> Self {
14 Self(id.into())
15 }
16
17 /// Returns the underlying id string.
18 pub fn as_str(&self) -> &str {
19 &self.0
20 }
21}
22
23impl From<&'static str> for CommandId {
24 fn from(value: &'static str) -> Self {
25 Self(Arc::<str>::from(value))
26 }
27}