LoaderContext

Struct LoaderContext 

Source
pub struct LoaderContext<'a, 'b, O: Send + Sync, I: Info> { /* private fields */ }
Expand description

Context for configuring the plugin loader.

LoaderContext provides a fluent interface for setting up the plugin loader with managers, functions, and requests. It ensures proper initialization order and provides convenient methods for loader configuration.

§Type Parameters

  • 'a - Lifetime for references within the loader
  • 'b - Lifetime of the loader reference
  • O - Output type for plugin functions (must implement Send + Sync)
  • I - Plugin information type (must implement Info trait)

§Fields

  • loader - Mutable reference to the underlying loader

§Example

use plux_rs::prelude::*;
use plux_custom_manager::CustomManager;

#[plux_rs::function]
fn my_function(_: ()) {
    // Function implementation
}
 
let mut loader = Loader::new();
loader.context(|mut ctx| {
    // Register a manager
    ctx.register_manager(CustomManager::new())?;

    // Register functions and requests
    ctx.register_function(my_function());
    ctx.register_request(Request::new("main".to_string(), vec![], None));

    Ok(())
});

Implementations§

Source§

impl<'a, 'b, O: Send + Sync, I: Info> LoaderContext<'a, 'b, O, I>

Source

pub fn register_manager<M>( &mut self, manager: M, ) -> Result<(), RegisterManagerError>
where M: Manager<'a, O, I> + 'static,

Registers a plugin manager with the loader.

This method registers a manager that can handle plugins of a specific format.

§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)
Source

pub fn register_managers<M>( &mut self, managers: M, ) -> Result<(), RegisterManagerError>
where M: IntoIterator<Item = Box<dyn Manager<'a, O, I>>>,

Registers multiple plugin managers with the loader.

This method registers a collection of managers in sequence.

§Parameters
  • managers - Iterator of manager instances to register
§Returns

Returns Result<(), RegisterManagerError> indicating success or failure.

Source

pub fn register_request(&mut self, request: Request)

Registers a function request with the loader.

Function requests define the interface that plugins must implement.

§Parameters
  • request - The request to register
Source

pub fn register_requests<IT>(&mut self, requests: IT)
where IT: IntoIterator<Item = Request>,

Registers multiple function requests with the loader.

This method registers a collection of requests.

§Parameters
  • requests - Iterator of requests to register
§Type Parameters
  • IT - Type of the iterator containing requests
Source

pub fn register_function<F>(&mut self, function: F)
where F: Function<Output = O> + 'static,

Registers a function in the loader’s registry.

Functions registered here are available to all plugins.

§Parameters
  • function - The function to register
§Type Parameters
  • F - Type of the function (must implement Function trait)
Source

pub fn register_functions<F, IT>(&mut self, functions: IT)
where F: Function<Output = O> + 'static, IT: IntoIterator<Item = F>,

Registers multiple functions in the loader’s registry.

This method registers a collection of functions.

§Parameters
  • functions - Iterator of functions to register
§Type Parameters
  • F - Type of the functions (must implement Function trait)
  • IT - Type of the iterator containing functions

Auto Trait Implementations§

§

impl<'a, 'b, O, I> Freeze for LoaderContext<'a, 'b, O, I>

§

impl<'a, 'b, O, I> !RefUnwindSafe for LoaderContext<'a, 'b, O, I>

§

impl<'a, 'b, O, I> Send for LoaderContext<'a, 'b, O, I>

§

impl<'a, 'b, O, I> Sync for LoaderContext<'a, 'b, O, I>

§

impl<'a, 'b, O, I> Unpin for LoaderContext<'a, 'b, O, I>

§

impl<'a, 'b, O, I> !UnwindSafe for LoaderContext<'a, 'b, O, I>

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

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.