pub trait Plugin:
Send
+ Sync
+ 'static {
// Required methods
fn manifest(&self) -> &PluginManifest;
fn register(&self, r: &mut PluginRegistrar<'_>) -> Result<(), PluginError>;
// Provided methods
fn init(&self, _cx: &PluginInitContext<'_>) -> Result<(), PluginError> { ... }
fn shutdown(&self) { ... }
}Expand description
The trait every uni-db extension implements.
A Plugin is a bundle of capability registrations: scalar functions,
aggregates, procedures, hooks, etc. The trait itself is small; all
per-surface detail lives in the capability traits in crate::traits.
§Examples
use std::sync::Arc;
use uni_plugin::{Plugin, PluginManifest, PluginRegistrar, PluginError};
pub struct NoopPlugin {
manifest: PluginManifest,
}
impl Plugin for NoopPlugin {
fn manifest(&self) -> &PluginManifest { &self.manifest }
fn register(&self, _r: &mut PluginRegistrar<'_>) -> Result<(), PluginError> {
Ok(())
}
}Required Methods§
Sourcefn manifest(&self) -> &PluginManifest
fn manifest(&self) -> &PluginManifest
Static plugin description.
Implementations typically store the manifest in a field and return a
borrow. The manifest is read at load time to compute the effective
capability set before Plugin::register is invoked.
Sourcefn register(&self, r: &mut PluginRegistrar<'_>) -> Result<(), PluginError>
fn register(&self, r: &mut PluginRegistrar<'_>) -> Result<(), PluginError>
Register extension points with the host.
Called exactly once at load time, after capability negotiation. The plugin uses the registrar’s typed builder methods to claim qualified names for each kind of extension.
§Errors
Returns PluginError::DuplicateRegistration if two registrations
claim the same QName, or PluginError::CapabilityRequired if a
registration requires a capability not in the effective set.
Provided Methods§
Sourcefn init(&self, _cx: &PluginInitContext<'_>) -> Result<(), PluginError>
fn init(&self, _cx: &PluginInitContext<'_>) -> Result<(), PluginError>
Optional initialization callback.
Called once after registration, in dependency order over the
manifest’s depends_on list. The default no-op is sufficient for
plugins that don’t need init-time setup.
§Errors
Plugins that fail initialization should return a PluginError;
the host will then unregister this plugin’s registrations and
propagate the error to the caller of Uni::add_plugin.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".