pub struct Api<O: Send + Sync + 'static, I: Info + 'static> { /* private fields */ }
Expand description
API interface provided to plugins during loading.
The Api struct provides a controlled interface for plugins to interact with the Plux system. It allows plugins to access the loader’s functionality while maintaining security boundaries and providing dependency-aware operations.
§Type Parameters
O
- Output type for plugin functions (must implement Send + Sync + ’static)I
- Plugin information type (must implement Info + ’static)
§Fields
loader
- Reference to the underlying loaderplugin
- Bundle information for the current plugindepends
- List of required dependencies for this pluginoptional_depends
- List of optional dependencies for this plugin
Implementations§
Source§impl<O: Send + Sync + 'static, I: Info + 'static> Api<O, I>
impl<O: Send + Sync + 'static, I: Info + 'static> Api<O, I>
Sourcepub fn registry(&self) -> &Registry<O>
pub fn registry(&self) -> &Registry<O>
Gets access to the function registry.
Returns a reference to the registry containing all functions available to plugins.
§Returns
Returns &Registry<O>
containing the function registry.
Sourcepub const fn plugin(&self) -> &Bundle
pub const fn plugin(&self) -> &Bundle
Gets information about the current plugin.
Returns the bundle information for the plugin this API instance belongs to.
§Returns
Returns &Bundle
containing plugin metadata.
Sourcepub const fn depends(&self) -> &Vec<Bundle>
pub const fn depends(&self) -> &Vec<Bundle>
Gets the list of required dependencies.
Returns all dependencies that must be available for this plugin to function.
§Returns
Returns &Vec<Bundle>
containing required dependencies.
Sourcepub const fn optional_depends(&self) -> &Vec<Bundle>
pub const fn optional_depends(&self) -> &Vec<Bundle>
Gets the list of optional dependencies.
Returns all optional dependencies that enhance this plugin’s functionality but are not required.
§Returns
Returns &Vec<Bundle>
containing optional dependencies.
Sourcepub fn register_manager<M>(
&self,
manager: M,
) -> Result<(), RegisterManagerError>where
M: Manager<'static, O, I> + 'static,
pub fn register_manager<M>(
&self,
manager: M,
) -> Result<(), RegisterManagerError>where
M: Manager<'static, O, I> + 'static,
Registers a plugin manager with the loader.
This method allows plugins to register new managers during execution.
§Parameters
manager
- The manager instance to register
§Returns
Returns Result<(), RegisterManagerError>
indicating success or failure.
§Type Parameters
M
- Type of the manager (must implement Manager trait)
Sourcepub fn register_managers<M>(
&self,
managers: M,
) -> Result<(), RegisterManagerError>
pub fn register_managers<M>( &self, managers: M, ) -> Result<(), RegisterManagerError>
Sourcepub fn par_register_managers<M>(
&self,
managers: M,
) -> Result<(), RegisterManagerError>
pub fn par_register_managers<M>( &self, managers: M, ) -> Result<(), RegisterManagerError>
Sourcepub fn unregister_manager(
&self,
format: &str,
) -> Result<(), UnregisterManagerError>
pub fn unregister_manager( &self, format: &str, ) -> Result<(), UnregisterManagerError>
Sourcepub fn par_get_manager_ref(
&self,
format: &str,
) -> Option<&Box<dyn Manager<'static, O, I>>>
pub fn par_get_manager_ref( &self, format: &str, ) -> Option<&Box<dyn Manager<'static, O, I>>>
Gets an immutable reference to a manager by format (parallel version).
This method allows plugins to access registered managers using parallel processing.
§Parameters
format
- The format of the manager to retrieve
§Returns
Returns Option<&Box<dyn Manager<'static, O, I>>>
containing the manager if found.
Sourcepub fn get_manager_mut(
&self,
format: &str,
) -> Option<&mut Box<dyn Manager<'static, O, I>>>
pub fn get_manager_mut( &self, format: &str, ) -> Option<&mut Box<dyn Manager<'static, O, I>>>
Sourcepub fn par_get_manager_mut(
&self,
format: &str,
) -> Option<&mut Box<dyn Manager<'static, O, I>>>
pub fn par_get_manager_mut( &self, format: &str, ) -> Option<&mut Box<dyn Manager<'static, O, I>>>
Gets a mutable reference to a manager by format (parallel version).
This method allows plugins to access registered managers for modification using parallel processing.
§Parameters
format
- The format of the manager to retrieve
§Returns
Returns Option<&mut Box<dyn Manager<'static, O, I>>>
containing the manager if found.
Sourcepub fn register_plugin(&self, path: &str) -> Result<Bundle, RegisterPluginError>
pub fn register_plugin(&self, path: &str) -> Result<Bundle, RegisterPluginError>
Sourcepub fn register_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, RegisterPluginError>where
P: IntoIterator<Item = &'b str>,
pub fn register_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, RegisterPluginError>where
P: IntoIterator<Item = &'b str>,
Registers multiple plugins with the loader.
This method allows plugins to register multiple plugins in sequence.
§Parameters
paths
- Iterator of paths to plugin files or directories
§Returns
Returns Result<Vec<Bundle>, RegisterPluginError>
containing the plugin bundles on success.
§Type Parameters
'b
- Lifetime of the path referencesP
- Type of the iterator containing path references
Sourcepub fn par_register_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, RegisterPluginError>where
P: IntoParallelIterator<Item = &'b str>,
pub fn par_register_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, RegisterPluginError>where
P: IntoParallelIterator<Item = &'b str>,
Registers multiple plugins with the loader in parallel.
This method allows plugins to register multiple plugins concurrently.
§Parameters
paths
- Parallel iterator of paths to plugin files or directories
§Returns
Returns Result<Vec<Bundle>, RegisterPluginError>
containing the plugin bundles on success.
§Type Parameters
'b
- Lifetime of the path referencesP
- Type of the parallel iterator containing path references
Sourcepub fn unregister_plugin(
&self,
id: &str,
version: &Version,
) -> Result<(), UnregisterPluginError>
pub fn unregister_plugin( &self, id: &str, version: &Version, ) -> Result<(), UnregisterPluginError>
Sourcepub fn unregister_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Result<(), UnregisterPluginError>
pub fn unregister_plugin_by_bundle( &self, bundle: &Bundle, ) -> Result<(), UnregisterPluginError>
Sourcepub fn par_unregister_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Result<(), UnregisterPluginError>
pub fn par_unregister_plugin_by_bundle( &self, bundle: &Bundle, ) -> Result<(), UnregisterPluginError>
Sourcepub fn load_plugin(
&self,
id: &str,
version: &Version,
) -> Result<(), LoadPluginError>
pub fn load_plugin( &self, id: &str, version: &Version, ) -> Result<(), LoadPluginError>
Sourcepub fn par_load_plugin(
&self,
id: &str,
version: &Version,
) -> Result<(), LoadPluginError>
pub fn par_load_plugin( &self, id: &str, version: &Version, ) -> Result<(), LoadPluginError>
Sourcepub fn load_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Result<(), LoadPluginError>
pub fn load_plugin_by_bundle( &self, bundle: &Bundle, ) -> Result<(), LoadPluginError>
Sourcepub fn par_load_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Result<(), LoadPluginError>
pub fn par_load_plugin_by_bundle( &self, bundle: &Bundle, ) -> Result<(), LoadPluginError>
Sourcepub fn load_plugin_now(
&self,
path: &str,
) -> Result<Bundle, PluginOperationError>
pub fn load_plugin_now( &self, path: &str, ) -> Result<Bundle, PluginOperationError>
Loads a plugin immediately from the specified path.
This convenience method allows plugins to register and load a plugin in a single operation.
§Parameters
path
- Path to the plugin file or directory
§Returns
Returns Result<Bundle, PluginOperationError>
containing the plugin bundle on success, or errors from registration or loading.
Sourcepub fn load_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>where
P: IntoIterator<Item = &'b str>,
pub fn load_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>where
P: IntoIterator<Item = &'b str>,
Loads multiple plugins from the specified paths.
This method allows plugins to register and load multiple plugins in sequence.
§Parameters
paths
- Iterator of paths to plugin files or directories
§Returns
Returns Result<Vec<Bundle>, PluginOperationError>
containing the plugin bundles on success, or errors from registration or loading.
§Type Parameters
'b
- Lifetime of the path referencesP
- Type of the iterator containing path references
Sourcepub fn par_load_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>where
P: IntoParallelIterator<Item = &'b str>,
pub fn par_load_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>where
P: IntoParallelIterator<Item = &'b str>,
Loads multiple plugins from the specified paths (parallel version).
This method allows plugins to register and load multiple plugins concurrently.
§Parameters
paths
- Parallel iterator of paths to plugin files or directories
§Returns
Returns Result<Vec<Bundle>, PluginOperationError>
containing the plugin bundles on success, or errors from registration or loading.
§Type Parameters
'b
- Lifetime of the path referencesP
- Type of the parallel iterator containing path references
Sourcepub fn load_only_used_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>where
P: IntoIterator<Item = &'b str>,
pub fn load_only_used_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>where
P: IntoIterator<Item = &'b str>,
Loads only the plugins that are used (not dependencies of other plugins).
This method allows plugins to register and load only the plugins that are not dependencies of other plugins, and automatically unregisters unused plugins.
§Parameters
paths
- Iterator of paths to plugin files or directories
§Returns
Returns Result<Vec<Bundle>, PluginOperationError>
containing the plugin bundles on success, or errors from registration, unregistration, or loading.
§Type Parameters
'b
- Lifetime of the path referencesP
- Type of the iterator containing path references
Sourcepub fn par_load_only_used_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>where
P: IntoParallelIterator<Item = &'b str>,
pub fn par_load_only_used_plugins<'b, P>(
&self,
paths: P,
) -> Result<Vec<Bundle>, PluginOperationError>where
P: IntoParallelIterator<Item = &'b str>,
Loads only the plugins that are used (not dependencies of other plugins) (parallel version).
This method allows plugins to register and load only the plugins that are not dependencies of other plugins using parallel processing, and automatically unregisters unused plugins.
§Parameters
paths
- Parallel iterator of paths to plugin files or directories
§Returns
Returns Result<Vec<Bundle>, PluginOperationError>
containing the plugin bundles on success, or errors from registration, unregistration, or loading.
§Type Parameters
'b
- Lifetime of the path referencesP
- Type of the parallel iterator containing path references
Sourcepub fn unload_plugin(
&self,
id: &str,
version: &Version,
) -> Result<(), UnloadPluginError>
pub fn unload_plugin( &self, id: &str, version: &Version, ) -> Result<(), UnloadPluginError>
Sourcepub fn par_unload_plugin(
&self,
id: &str,
version: &Version,
) -> Result<(), UnloadPluginError>
pub fn par_unload_plugin( &self, id: &str, version: &Version, ) -> Result<(), UnloadPluginError>
Unloads a plugin from the execution environment (parallel version).
This method allows plugins to unload other plugins by ID and version using parallel processing.
§Parameters
id
- Plugin identifierversion
- Plugin version
§Returns
Returns Result<(), UnloadPluginError>
indicating success or failure.
Sourcepub fn unload_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Result<(), UnloadPluginError>
pub fn unload_plugin_by_bundle( &self, bundle: &Bundle, ) -> Result<(), UnloadPluginError>
Sourcepub fn par_unload_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Result<(), UnloadPluginError>
pub fn par_unload_plugin_by_bundle( &self, bundle: &Bundle, ) -> Result<(), UnloadPluginError>
Unloads a plugin from the execution environment by bundle (parallel version).
This method allows plugins to unload other plugins by bundle information using parallel processing.
§Parameters
bundle
- Plugin bundle information
§Returns
Returns Result<(), UnloadPluginError>
indicating success or failure.
Sourcepub fn par_get_plugin(
&self,
id: &str,
version: &Version,
) -> Option<&Plugin<'static, O, I>>
pub fn par_get_plugin( &self, id: &str, version: &Version, ) -> Option<&Plugin<'static, O, I>>
Gets an immutable reference to a plugin by ID and version (parallel version).
This method allows plugins to access other registered plugins using parallel processing.
§Parameters
id
- Plugin identifierversion
- Plugin version
§Returns
Returns Option<&Plugin<'static, O, I>>
containing the plugin if found.
Sourcepub fn get_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Option<&Plugin<'static, O, I>>
pub fn get_plugin_by_bundle( &self, bundle: &Bundle, ) -> Option<&Plugin<'static, O, I>>
Sourcepub fn par_get_plugin_by_bundle(
&self,
bundle: &Bundle,
) -> Option<&Plugin<'static, O, I>>
pub fn par_get_plugin_by_bundle( &self, bundle: &Bundle, ) -> Option<&Plugin<'static, O, I>>
Gets an immutable reference to a plugin by bundle (parallel version).
This method allows plugins to access other registered plugins by bundle information using parallel processing.
§Parameters
bundle
- Plugin bundle information
§Returns
Returns Option<&Plugin<'static, O, I>>
containing the plugin if found.
Sourcepub fn get_plugin_mut(
&self,
id: &str,
version: &Version,
) -> Option<&mut Plugin<'static, O, I>>
pub fn get_plugin_mut( &self, id: &str, version: &Version, ) -> Option<&mut Plugin<'static, O, I>>
Sourcepub fn par_get_plugin_mut(
&self,
id: &str,
version: &Version,
) -> Option<&mut Plugin<'static, O, I>>
pub fn par_get_plugin_mut( &self, id: &str, version: &Version, ) -> Option<&mut Plugin<'static, O, I>>
Gets a mutable reference to a plugin by ID and version (parallel version).
This method allows plugins to access other registered plugins for modification using parallel processing.
§Parameters
id
- Plugin identifierversion
- Plugin version
§Returns
Returns Option<&mut Plugin<'static, O, I>>
containing the plugin if found.
Sourcepub fn get_plugin_mut_by_bundle(
&self,
bundle: &Bundle,
) -> Option<&mut Plugin<'static, O, I>>
pub fn get_plugin_mut_by_bundle( &self, bundle: &Bundle, ) -> Option<&mut Plugin<'static, O, I>>
Sourcepub fn par_get_plugin_mut_by_bundle(
&self,
bundle: &Bundle,
) -> Option<&mut Plugin<'static, O, I>>
pub fn par_get_plugin_mut_by_bundle( &self, bundle: &Bundle, ) -> Option<&mut Plugin<'static, O, I>>
Gets a mutable reference to a plugin by bundle (parallel version).
This method allows plugins to access other registered plugins for modification by bundle information using parallel processing.
§Parameters
bundle
- Plugin bundle information
§Returns
Returns Option<&mut Plugin<'static, O, I>>
containing the plugin if found.
Sourcepub fn get_plugins_by_id(&self, id: &str) -> Vec<&Plugin<'static, O, I>>
pub fn get_plugins_by_id(&self, id: &str) -> Vec<&Plugin<'static, O, I>>
Sourcepub fn par_get_plugins_by_id(&self, id: &str) -> Vec<&Plugin<'static, O, I>>
pub fn par_get_plugins_by_id(&self, id: &str) -> Vec<&Plugin<'static, O, I>>
Sourcepub fn get_plugins_by_id_mut(&self, id: &str) -> Vec<&mut Plugin<'static, O, I>>
pub fn get_plugins_by_id_mut(&self, id: &str) -> Vec<&mut Plugin<'static, O, I>>
Sourcepub fn par_get_plugins_by_id_mut(
&self,
id: &str,
) -> Vec<&mut Plugin<'static, O, I>>
pub fn par_get_plugins_by_id_mut( &self, id: &str, ) -> Vec<&mut Plugin<'static, O, I>>
Gets mutable references to all plugins with the specified ID (parallel version).
This method allows plugins to access all versions of plugins with a specific ID for modification using parallel processing.
§Parameters
id
- Plugin identifier to search for
§Returns
Returns Vec<&mut Plugin<'static, O, I>>
containing all matching plugins.
Sourcepub fn get_plugins(&self) -> &Vec<Plugin<'static, O, I>>
pub fn get_plugins(&self) -> &Vec<Plugin<'static, O, I>>
Gets a reference to all loaded plugins.
This method allows plugins to access the complete list of loaded plugins.
§Returns
Returns &Vec<Plugin<'static, O, I>>
containing all loaded plugins.
Sourcepub fn get_registry(&self) -> &Registry<O>
pub fn get_registry(&self) -> &Registry<O>
Gets a reference to the function registry.
This method allows plugins to access the registry of functions available to plugins.
§Returns
Returns &Registry<O>
containing the function registry.
Sourcepub fn get_requests(&self) -> &Requests
pub fn get_requests(&self) -> &Requests
Gets a reference to the function requests.
This method allows plugins to access the collection of function requests.
§Returns
Returns &Requests
containing the function requests.
Sourcepub fn call_request(
&self,
name: &str,
args: &[Variable],
) -> Result<Vec<O>, PluginCallRequestError>
pub fn call_request( &self, name: &str, args: &[Variable], ) -> Result<Vec<O>, PluginCallRequestError>
Calls a function request across all eligible plugins.
This method allows plugins to call a function request on all plugins that have the highest version for their ID (to avoid calling multiple versions of the same plugin).
§Parameters
name
- Name of the function request to callargs
- Arguments to pass to the function
§Returns
Returns Result<Vec<O>, PluginCallRequestError>
containing results from all
eligible plugins that have the requested function.
Sourcepub fn par_call_request(
&self,
name: &str,
args: &[Variable],
) -> Result<Vec<O>, PluginCallRequestError>
pub fn par_call_request( &self, name: &str, args: &[Variable], ) -> Result<Vec<O>, PluginCallRequestError>
Calls a function request across all eligible plugins (parallel version).
This method allows plugins to call a function request on all plugins that have the highest version for their ID using parallel processing.
§Parameters
name
- Name of the function request to callargs
- Arguments to pass to the function
§Returns
Returns Result<Vec<O>, PluginCallRequestError>
containing results from all
eligible plugins that have the requested function.
Sourcepub fn call_function_depend(
&self,
id: &str,
version: &Version,
name: &str,
args: &[Variable],
) -> Result<O, CallFunctionDependError>
pub fn call_function_depend( &self, id: &str, version: &Version, name: &str, args: &[Variable], ) -> Result<O, CallFunctionDependError>
Calls a function on a required dependency.
This method allows the current plugin to call functions exposed by its required dependencies. It ensures that the dependency exists and is loaded before attempting the call.
§Parameters
id
- Dependency plugin IDversion
- Dependency plugin versionname
- Function name to callargs
- Arguments to pass to the function
§Returns
Returns Result<O, CallFunctionDependError>
containing the function result on success,
or an error if the dependency is not found or the function call fails.
§Note
This method only works with required dependencies. For optional dependencies,
use call_function_optional_depend
.
Sourcepub fn call_function_optional_depend(
&self,
id: &str,
version: &Version,
name: &str,
args: &[Variable],
) -> Result<Option<O>, PluginCallFunctionError>
pub fn call_function_optional_depend( &self, id: &str, version: &Version, name: &str, args: &[Variable], ) -> Result<Option<O>, PluginCallFunctionError>
Calls a function on an optional dependency.
This method allows the current plugin to call functions exposed by its optional dependencies.
Unlike required dependencies, this method returns None
if the dependency is not available.
§Parameters
id
- Optional dependency plugin IDversion
- Optional dependency plugin versionname
- Function name to callargs
- Arguments to pass to the function
§Returns
Returns Result<Option<O>, PluginCallFunctionError>
containing:
Ok(Some(result))
if the dependency exists and the call succeedsOk(None)
if the dependency is not availableErr(error)
if the function call fails
§Note
This method only works with optional dependencies. For required dependencies,
use call_function_depend
.
Auto Trait Implementations§
impl<O, I> !Freeze for Api<O, I>
impl<O, I> !RefUnwindSafe for Api<O, I>
impl<O, I> Send for Api<O, I>
impl<O, I> Sync for Api<O, I>
impl<O, I> Unpin for Api<O, I>
impl<O, I> !UnwindSafe for Api<O, I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more