Skip to main content

PluginManager

Struct PluginManager 

Source
pub struct PluginManager { /* private fields */ }
Expand description

插件管理器:负责注册、拓扑排序启动、逆序关闭

§示例

let mgr = PluginManager::new()
    .add(db_plugin)
    .add(cache_plugin);
mgr.start_all().await?;
// ... 运行应用 ...
mgr.stop_all().await;

Implementations§

Source§

impl PluginManager

Source

pub fn new() -> Self

创建空的插件管理器

Source

pub fn add<P: Plugin + 'static>(self, plugin: P) -> Self

手动注册插件(链式调用)

§示例
PluginManager::new()
    .add(DbPlugin::new(db_config))
    .add(CachePlugin::new(cache_config))
Source

pub fn add_discovered(self, plugins: Vec<Box<dyn Plugin>>) -> Self

编译期自动发现的插件批量注册

#[plugin] 宏配合使用,将 linkme 收集到的插件批量加入管理器。

Source

pub async fn start_all(&self) -> Result<()>

拓扑排序后依次启动所有插件

若任一插件启动失败,流程立即中止并返回错误。

Source

pub async fn stop_all(&self)

逆序关闭所有插件(后启动的先关闭)

即使某个插件关闭失败,也会继续关闭其余插件(仅记录错误日志)。

Source

pub fn check_duplicate_names(&self) -> Result<(), String>

确保插件之间没有 name 冲突

Trait Implementations§

Source§

impl Default for PluginManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more