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 referencesO
- 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 loadedrequests
- 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>
impl<'a, 'b, O: Send + Sync, I: Info> LoadPluginContext<'a, 'b, O, I>
Sourcepub const fn requests(&self) -> &'b Requests
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.
Sourcepub fn register_request<F>(
&mut self,
request: F,
) -> Result<(), RegisterRequestError>where
F: Function<Output = O> + 'static,
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> 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> 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