LoadPluginContext

Struct LoadPluginContext 

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

Context provided during plugin loading.

LoadPluginContext gives plugin managers access to the plugin being loaded and the system’s function requests. It allows managers to register plugin functions and validate them against the expected interface.

§Type Parameters

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

§Fields

  • plugin - Mutable reference to the plugin being loaded
  • requests - Reference to the system’s function requests

§Example

use plux_rs::{Manager, utils::ManagerResult, LoadPluginContext, RegisterPluginContext, Api, StdInfo};

struct MyManager;

impl Manager<'_, (), StdInfo> for MyManager {
    fn format(&self) -> &'static str { "my" }
 
    fn register_plugin(&mut self, _context: RegisterPluginContext) -> ManagerResult<StdInfo> {
        Ok(StdInfo::new())
    }

    fn load_plugin(
        &mut self,
        context: LoadPluginContext<'_, '_, (), StdInfo>,
        api: Api<(), StdInfo>
    ) -> ManagerResult<()> {
        // Register plugin functions that match the requests
        for request in context.requests() {
            // Register corresponding function in the plugin
        }
        Ok(())
    }
}

Implementations§

Source§

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

Source

pub const fn plugin(&'b self) -> &'b Plugin<'a, O, I>

Gets a reference to the plugin being loaded.

§Returns

Returns an immutable reference to the plugin.

Source

pub const fn requests(&self) -> &'b Requests

Gets a reference to the system’s function requests.

§Returns

Returns a reference to the requests that plugins should implement.

Source

pub fn register_request<F>( &mut self, request: F, ) -> Result<(), RegisterRequestError>
where F: Function<Output = O> + 'static,

Registers a function that implements a system request.

This method validates that the provided function matches the signature of a registered system request and then registers it with the plugin.

§Parameters
  • request - The function that implements a system request
§Returns

Returns Result<(), RegisterRequestError> indicating success or failure. Fails if the function doesn’t match any registered request or has incorrect arguments.

§Type Parameters
  • F - Type of the function (must implement Function trait)

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, 'b, O, I> !UnwindSafe for LoadPluginContext<'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.