pub struct PluginLoader { /* private fields */ }Expand description
Plugin loader for dynamic loading and instantiation.
The PluginLoader handles the runtime loading of plugin libraries,
symbol resolution, and plugin instantiation. It supports various
plugin formats and provides caching for performance.
§Supported Formats
- Dynamic libraries (.so, .dll, .dylib)
- WebAssembly modules (.wasm)
- Static plugins (compiled-in)
§Example
use trustformers_core::plugins::{PluginLoader, PluginInfo};
use std::path::Path;
let loader = PluginLoader::new();
// Load plugin info from metadata
let info = loader.load_plugin_info(Path::new("plugins/custom_attention.so")).unwrap();
// Load the actual plugin
let plugin = loader.load_plugin(&info).unwrap();Implementations§
Source§impl PluginLoader
impl PluginLoader
Sourcepub fn with_config(config: LoaderConfig) -> Self
pub fn with_config(config: LoaderConfig) -> Self
Sourcepub fn load_plugin_info<P: AsRef<Path>>(&self, path: P) -> Result<PluginInfo>
pub fn load_plugin_info<P: AsRef<Path>>(&self, path: P) -> Result<PluginInfo>
Sourcepub fn load_plugin(&self, info: &PluginInfo) -> Result<Box<dyn Plugin>>
pub fn load_plugin(&self, info: &PluginInfo) -> Result<Box<dyn Plugin>>
Sourcepub fn register_static_plugin(
&self,
name: &str,
factory: StaticPluginFactory,
) -> Result<()>
pub fn register_static_plugin( &self, name: &str, factory: StaticPluginFactory, ) -> Result<()>
Registers a static plugin factory.
Static plugins are compiled into the binary and don’t require dynamic loading. This method registers a factory function that can create instances of the plugin.
§Arguments
name- Plugin namefactory- Factory function for creating plugin instances
§Returns
Ok(()) on successful registration.
Sourcepub fn unload_library(&self, name: &str) -> Result<()>
pub fn unload_library(&self, name: &str) -> Result<()>
Sourcepub fn clear_cache(&self) -> Result<()>
pub fn clear_cache(&self) -> Result<()>
Clears all cached libraries.
Sourcepub fn stats(&self) -> Result<LoaderStats>
pub fn stats(&self) -> Result<LoaderStats>
Trait Implementations§
Source§impl Debug for PluginLoader
impl Debug for PluginLoader
Auto Trait Implementations§
impl Freeze for PluginLoader
impl RefUnwindSafe for PluginLoader
impl Send for PluginLoader
impl Sync for PluginLoader
impl Unpin for PluginLoader
impl UnsafeUnpin for PluginLoader
impl UnwindSafe for PluginLoader
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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