fusion_core/plugin/
mod.rs1use crate::application::ApplicationBuilder;
2use async_trait::async_trait;
3use std::{any::Any, ops::Deref, sync::Arc};
4
5#[derive(Clone)]
7pub struct PluginRef(Arc<dyn Plugin>);
8
9#[async_trait]
11pub trait Plugin: Any + Send + Sync {
12 async fn build(&self, _app: &mut ApplicationBuilder) {}
14
15 fn immediately_build(&self, _app: &mut ApplicationBuilder) {}
19
20 fn name(&self) -> &str {
23 std::any::type_name::<Self>()
24 }
25
26 fn dependencies(&self) -> Vec<&str> {
28 vec![]
29 }
30
31 fn immediately(&self) -> bool {
33 false
34 }
35}
36
37impl PluginRef {
38 pub(crate) fn new<T: Plugin>(plugin: T) -> Self {
39 Self(Arc::new(plugin))
40 }
41}
42
43impl Deref for PluginRef {
44 type Target = dyn Plugin;
45
46 fn deref(&self) -> &Self::Target {
47 &*self.0
48 }
49}