satex_core/component/
mod.rs1mod args;
2mod configurable;
3
4use serde::{Deserialize, Serialize};
5use serde_yaml::Value;
6
7pub use args::*;
8pub use configurable::*;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(untagged)]
12pub enum Component {
13 Shortcut(String),
14 Full {
15 kind: String,
16 #[serde(default)]
17 args: Value,
18 },
19}
20
21impl Component {
22 pub fn kind(&self) -> &str {
23 match self {
24 Component::Shortcut(text) => text.split_once('=').map(|(name, _)| name).unwrap_or(text),
25 Component::Full { kind, .. } => kind,
26 }
27 }
28
29 pub fn args(&self) -> Args {
30 match self {
31 Component::Shortcut(text) => match text.split_once('=').map(|(_, item)| item) {
32 Some(args) => Args::Shortcut(Some(args)),
33 None => Args::Shortcut(None),
34 },
35 Component::Full { args, .. } => Args::Full(args),
36 }
37 }
38
39 pub fn is_shortcut(&self) -> bool {
40 matches!(self, Component::Shortcut(_))
41 }
42
43 pub fn is_full(&self) -> bool {
44 matches!(self, Component::Full { .. })
45 }
46}