moduforge_runtime/
extension.rs

1use std::sync::Arc;
2
3use moduforge_core::state::plugin::Plugin;
4
5use crate::types::GlobalAttributeItem;
6///扩展实现
7/// 组装全局属性和插件
8#[derive(Clone, Default, Debug)]
9pub struct Extension {
10    global_attributes: Vec<GlobalAttributeItem>,
11    plugins: Vec<Arc<Plugin>>,
12}
13unsafe impl Send for Extension {}
14unsafe impl Sync for Extension {}
15impl Extension {
16    pub fn new() -> Self {
17        Extension { global_attributes: vec![], plugins: vec![] }
18    }
19    pub fn add_global_attribute(
20        &mut self,
21        item: GlobalAttributeItem,
22    ) -> &mut Self {
23        self.global_attributes.push(item);
24        self
25    }
26    pub fn get_global_attributes(&self) -> &Vec<GlobalAttributeItem> {
27        &self.global_attributes
28    }
29    pub fn add_plugin(
30        &mut self,
31        plugin: Arc<Plugin>,
32    ) -> &mut Self {
33        self.plugins.push(plugin);
34        self
35    }
36    pub fn get_plugins(&self) -> &Vec<Arc<Plugin>> {
37        &self.plugins
38    }
39}