Skip to main content

zerolaunch_plugin_api/config/
component_core.rs

1use crate::config::component_type::ComponentType;
2
3/// 所有组件共享的身份信息核心。
4///
5/// 内置插件与远程插件采用同一身份模型:
6/// 一个逻辑组件无论 kind 是什么,其 `component_id`、`component_name`、
7/// `component_description`、`component_type`、`priority` 都统一存放在
8/// `ComponentCore` 中,避免在多个 struct 或 trait 实现里重复硬编码。
9///
10/// ComponentCore 不包含 settings —— settings 的存储模式因组件而异:
11/// 内置插件使用强类型 struct(如 `AppearanceSettings`),远程插件使用
12/// `serde_json::Value`。这里强制统一反而导致死存储,见 `decisions.md 第7条`。
13pub struct ComponentCore {
14    pub(crate) component_id: String,
15    pub(crate) component_name: String,
16    pub(crate) component_description: String,
17    pub(crate) component_type: ComponentType,
18    pub(crate) priority: u32,
19}
20
21impl ComponentCore {
22    pub fn new(
23        component_id: String,
24        component_name: String,
25        component_description: String,
26        component_type: ComponentType,
27        priority: u32,
28    ) -> Self {
29        Self {
30            component_id,
31            component_name,
32            component_description,
33            component_type,
34            priority,
35        }
36    }
37
38    pub fn component_id(&self) -> &str {
39        &self.component_id
40    }
41
42    pub fn component_name(&self) -> &str {
43        &self.component_name
44    }
45
46    pub fn component_description(&self) -> &str {
47        &self.component_description
48    }
49
50    pub fn component_type(&self) -> ComponentType {
51        self.component_type
52    }
53
54    pub fn priority(&self) -> u32 {
55        self.priority
56    }
57}
58
59impl std::fmt::Debug for ComponentCore {
60    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61        f.debug_struct("ComponentCore")
62            .field("component_id", &self.component_id)
63            .field("component_name", &self.component_name)
64            .field("component_description", &self.component_description)
65            .field("component_type", &self.component_type)
66            .field("priority", &self.priority)
67            .finish()
68    }
69}