Skip to main content

PluginService

Struct PluginService 

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

插件服务

提供插件的管理、调用、状态检查等功能

对应 TypeScript 版本的 PluginService

Implementations§

Source§

impl PluginService

Source

pub fn new(registry: Arc<PluginRegistry>) -> Self

创建插件服务

Source

pub fn from_global() -> Self

从全局注册表创建插件服务

注意:由于 Rust 的所有权模型,这里创建一个新的服务实例, 但会使用全局注册表。实际使用时,建议通过依赖注入传递同一个注册表实例。

Source

pub fn with_registry(registry: Arc<PluginRegistry>) -> Self

使用指定的注册表创建插件服务

Source

pub fn get_config(&self, key: &str) -> Option<Value>

获取插件配置

对应 TypeScript 版本的 getConfig

Source

pub fn set_config(&self, key: &str, config: Value)

设置插件配置

Source

pub async fn invoke( &self, key: &str, method: &str, params: Value, ) -> PluginResult<Value>

调用插件方法

对应 TypeScript 版本的 invoke

§示例
let service = PluginService::from_global();
let result = service.invoke("upload", "upload", json!({
    "file": "..."
})).await?;
Source

pub fn get_instance( &self, key: &str, ) -> PluginResult<Arc<Mutex<Box<dyn Plugin>>>>

获取插件实例

对应 TypeScript 版本的 getInstance

注意:由于 Rust 的类型系统限制,这里返回的是插件的 Arc 引用

Source

pub fn check_status(&self, key: &str) -> PluginResult<()>

检查插件状态

对应 TypeScript 版本的 checkStatus

Source

pub fn set_status(&self, key: &str, status: PluginStatus)

设置插件状态

Source

pub fn enable(&self, key: &str) -> PluginResult<()>

启用插件

Source

pub fn disable(&self, key: &str) -> PluginResult<()>

禁用插件

Source

pub fn get_info(&self, key: &str) -> PluginResult<PluginInfo>

获取插件信息

Source

pub fn list(&self) -> Vec<PluginInfo>

获取所有插件信息

对应 TypeScript 版本的 list

Source

pub fn get_by_hook(&self, hook: &str) -> Vec<PluginInfo>

获取指定钩子类型的插件

Source

pub async fn re_init(&self, key: &str) -> PluginResult<()>

重新初始化插件

对应 TypeScript 版本的 reInit

Source

pub fn remove(&self, key: &str) -> PluginResult<()>

移除插件

对应 TypeScript 版本的 remove

Trait Implementations§

Source§

impl Default for PluginService

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