Skip to main content

PluginHandle

Struct PluginHandle 

Source
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

Source

pub fn from_loaded(plugin: LoadedPlugin) -> Self

Create a PluginHandle from a LoadedPlugin.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn info(&self) -> &PluginInfo

Access the plugin’s owned metadata.

Source

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.

Source

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.

Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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