pub struct PluginHandle { /* private fields */ }Expand description
A handle to a loaded plugin, ready for calling methods.
Holds an Arc<Library> to keep the dylib loaded as long as any handle exists.
Call methods via call_method() which handles serialization, FFI, and cleanup.
PluginHandle is Send + Sync. Plugin methods take &self (enforced by
the macro), so concurrent calls from multiple threads are safe as long as
the plugin implementation is thread-safe internally.
Implementations§
Source§impl PluginHandle
impl PluginHandle
Sourcepub fn from_loaded(plugin: LoadedPlugin) -> Self
pub fn from_loaded(plugin: LoadedPlugin) -> Self
Create a PluginHandle from a LoadedPlugin.
Sourcepub fn from_descriptor(
desc: &'static PluginDescriptor,
) -> Result<Self, LoadError>
pub fn from_descriptor( desc: &'static PluginDescriptor, ) -> Result<Self, LoadError>
Create a PluginHandle from a plugin descriptor already registered in
the current process’s inventory (via a #[plugin_impl] linked into
the current binary as a normal rlib). No dylib is loaded — the
descriptor’s vtable points at code in the current binary.
Used by the generated Client::in_process(plugin_name) constructor.
Host applications normally use PluginHandle::from_loaded instead.
Sourcepub fn find_in_process_descriptor(
plugin_name: &str,
) -> Result<&'static PluginDescriptor, LoadError>
pub fn find_in_process_descriptor( plugin_name: &str, ) -> Result<&'static PluginDescriptor, LoadError>
Look up a descriptor in the current process’s inventory registry by
plugin_name (the Rust struct name that was passed to #[plugin_impl]).
Returns LoadError::PluginNotFound if no descriptor has that name.
The returned reference has 'static lifetime because descriptors
emitted by #[plugin_impl] live in the binary’s .rodata.
Sourcepub fn call_method<I: Serialize, O: DeserializeOwned>(
&self,
index: usize,
input: &I,
) -> Result<O, CallError>
pub fn call_method<I: Serialize, O: DeserializeOwned>( &self, index: usize, input: &I, ) -> Result<O, CallError>
Call a plugin method by vtable index.
Serializes the input, calls the FFI function pointer at the given index, checks the status code, deserializes the output, and frees the plugin-allocated buffer.
§Arguments
index- The method index in the vtable (0-based, in declaration order)input- The input argument to serialize and pass to the plugin
§No timeout
This call runs synchronously on the calling thread and has no built-in
timeout or cancellation. A misbehaving plugin will block the caller
indefinitely. See the fidius crate top-level docs (“What fidius
does not provide”) for the rationale and the recommended consumer-side
mitigation.
Sourcepub fn call_method_raw(
&self,
index: usize,
input: &[u8],
) -> Result<Vec<u8>, CallError>
pub fn call_method_raw( &self, index: usize, input: &[u8], ) -> Result<Vec<u8>, CallError>
Call a plugin method whose argument and successful return value are
raw bytes — bypassing bincode on both sides. Used by methods declared
with #[wire(raw)] on the interface trait.
Errors and panic messages still use bincode (small typed payloads).
Returns the success bytes on Ok, or a CallError::Plugin(_) whose
inner PluginError was bincode-decoded from the plugin’s error payload.
Same no-timeout caveat as Self::call_method.
Sourcepub fn has_capability(&self, bit: u32) -> bool
pub fn has_capability(&self, bit: u32) -> bool
Check if an optional method is supported (capability bit is set).
Returns false for bit indices >= 64 rather than panicking.
Sourcepub fn info(&self) -> &PluginInfo
pub fn info(&self) -> &PluginInfo
Access the plugin’s owned metadata.
Sourcepub fn method_metadata(&self, method_id: u32) -> Vec<(&str, &str)>
pub fn method_metadata(&self, method_id: u32) -> Vec<(&str, &str)>
Returns the static key/value metadata declared on the given method via
#[method_meta(...)] attributes on the trait, in declaration order.
Returns an empty Vec if:
method_id >= method_count(out of range)- the interface declared no method metadata on any method
- this specific method has no metadata declared
The returned &str slices borrow from the loaded library’s .rodata
(for dylib-loaded handles) or from the current binary’s .rodata
(for in-process handles). The handle’s lifetime bounds them safely.
Sourcepub fn trait_metadata(&self) -> Vec<(&str, &str)>
pub fn trait_metadata(&self) -> Vec<(&str, &str)>
Returns the static key/value metadata declared on the trait via
#[trait_meta(...)] attributes, in declaration order.
Returns an empty Vec if no trait-level metadata was declared.