spring_boot/plugin/
mod.rs

1pub mod component;
2
3use crate::app::AppBuilder;
4use async_trait::async_trait;
5use std::{any::Any, ops::Deref, sync::Arc};
6
7#[derive(Clone)]
8pub struct PluginRef(Arc<dyn Plugin>);
9
10#[async_trait]
11pub trait Plugin: Any + Send + Sync {
12    /// Configures the `App` to which this plugin is added.
13    async fn build(&self, app: &mut AppBuilder);
14
15    /// Configures a name for the [`Plugin`] which is primarily used for checking plugin
16    /// uniqueness and debugging.
17    fn name(&self) -> &str {
18        std::any::type_name::<Self>()
19    }
20
21    /// A list of plugins to depend on. The plugin will be built after the plugins in this list.
22    fn dependencies(&self) -> Vec<&str> {
23        vec![]
24    }
25}
26
27impl PluginRef {
28    pub(crate) fn new<T: Plugin>(plugin: T) -> Self {
29        Self(Arc::new(plugin))
30    }
31}
32
33impl Deref for PluginRef {
34    type Target = dyn Plugin;
35
36    fn deref(&self) -> &Self::Target {
37        &*self.0
38    }
39}