moduforge_runtime/
extension.rs

1use std::sync::Arc;
2
3use moduforge_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}
13
14unsafe impl Send for Extension {}
15unsafe impl Sync for Extension {}
16
17impl Extension {
18    pub fn new() -> Self {
19        Extension { global_attributes: vec![], plugins: vec![] }
20    }
21    pub fn add_global_attribute(
22        &mut self,
23        item: GlobalAttributeItem,
24    ) -> &mut Self {
25        self.global_attributes.push(item);
26        self
27    }
28    pub fn get_global_attributes(&self) -> &Vec<GlobalAttributeItem> {
29        &self.global_attributes
30    }
31    pub fn add_plugin(
32        &mut self,
33        plugin: Arc<Plugin>,
34    ) -> &mut Self {
35        self.plugins.push(plugin);
36        self
37    }
38    pub fn get_plugins(&self) -> &Vec<Arc<Plugin>> {
39        &self.plugins
40    }
41}