Skip to main content

CratePluginKit

Struct CratePluginKit 

Source
pub struct CratePluginKit<T> { /* private fields */ }
Expand description

通用插件管理库。

建一个、串行用。

Implementations§

Source§

impl<T> CratePluginKit<T>

Source

pub fn new(cfg: KitConfig) -> KitResult<Self>

按配置建一个 kit 实例。会创建数据目录。

Source

pub fn config(&self) -> &KitConfig

配置。

Source

pub fn paths(&self) -> &KitPaths

各项路径。

Source

pub fn registry(&self) -> &Registry

registry 客户端。

Source

pub fn install(&self, name: &str, version: Option<&str>) -> KitResult<Installed>

安装一个插件。

name 可以写短名("cargo",会自动补 KitConfig::crate_prefix), 也可以写完整 crate 名。version 给 None 就去 crates.io 查最新版。

§Errors
Source

pub fn update(&self, name: &str, version: Option<&str>) -> KitResult<Installed>

更新(或重装)一个插件。已存在就替换,不存在就当安装。

Source

pub fn uninstall(&self, name: &str) -> KitResult<()>

卸载一个插件。

§Errors
  • KitError::NotInstalled:本来就没装。
  • KitError::PluginPanicked 之外的一个“正在使用“错误:本进程加载过它的库。 Windows 上正在 dlopen 的 .dll 删不掉;Linux 上删得掉但空间不回收。 与其赌,不如让用户换一个干净的进程。
Source

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

列出已安装的插件。

以磁盘上的 manifest 为准,.plugins.json 只用来补充“来源 / 安装时间“ 这类 manifest 里没有的信息。所以缓存丢了也不会漏插件。

Source

pub fn manifest_of(&self, name: &str) -> KitResult<PluginManifest>

读某个插件的 manifest。

Source

pub fn resolve(&self, name: &str, relative: impl AsRef<Path>) -> PathBuf

把 name 下的相对路径解析成绝对路径。

Source

pub fn load(&self, name: &str) -> KitResult<LoadedPlugin<T>>

加载插件,拿到 *const T。

加载过之后 Self::uninstall 会拒绝删除它,直到进程退出。

Source

pub fn search( &self, keyword: &str, limit: usize, ) -> KitResult<Vec<CrateSummary>>

搜 crate。

Source

pub fn view(&self, name: &str) -> KitResult<Option<CrateInfo>>

按精确名查 crate。

Auto Trait Implementations§

§

impl<T> !Freeze for CratePluginKit<T>

§

impl<T> !RefUnwindSafe for CratePluginKit<T>

§

impl<T> !Sync for CratePluginKit<T>

§

impl<T> Send for CratePluginKit<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Unpin for CratePluginKit<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for CratePluginKit<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for CratePluginKit<T>
where PhantomData<fn() -> T>: UnwindSafe,

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, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.