pub struct Plugin<'a> { /* private fields */ }
Expand description
Plugin interface.
Methods are loaded using libloading
. If required methods aren’t found,
the plugin isn’t loaded. All optional methods are checked first, before being
executed.
Using this interface is reasonably safe.
Implementations§
Source§impl<'a> Plugin<'a>
impl<'a> Plugin<'a>
Sourcepub fn library<P: AsRef<Path>>(name: P) -> Result<Library, Error>
pub fn library<P: AsRef<Path>>(name: P) -> Result<Library, Error>
Load plugin’s shared library using a cross-platform naming convention.
Plugin has to be in LD_LIBRARY_PATH
, in a standard location
for the operating system, or be provided as an absolute or relative path,
including the platform-specific extension.
§Example
use pgdog_plugin::Plugin;
let plugin_lib = Plugin::library("/home/pgdog/plugin.so").unwrap();
let plugin_lib = Plugin::library("plugin.so").unwrap();
Sourcepub fn load(name: &str, library: &'a Library) -> Self
pub fn load(name: &str, library: &'a Library) -> Self
Load standard plugin methods from the plugin library.
§Arguments
name
: Plugin name. Can be any name you want, it’s only used for logging.library
:libloading::Library
reference. Must have the same, ideally static, lifetime as the plugin.
Sourcepub fn init(&self) -> bool
pub fn init(&self) -> bool
Execute plugin’s initialization routine. Returns true if the route exists and was executed, false otherwise.
Sourcepub fn route(&self, context: PdRouterContext) -> Option<PdRoute>
pub fn route(&self, context: PdRouterContext) -> Option<PdRoute>
Execute plugin’s route routine. Determines where a statement should be sent.
Returns a route if the routine is defined, or None
if not.
§Arguments
context
: Statement context created by PgDog’s query router.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns plugin’s name. This is the same name as what
is passed to Plugin::load
function.
Sourcepub fn rustc_version(&self) -> Option<PdStr>
pub fn rustc_version(&self) -> Option<PdStr>
Returns the Rust compiler version used to build the plugin. This version must match the compiler version used to build PgDog, or the plugin won’t be loaded.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Plugin<'a>
impl<'a> RefUnwindSafe for Plugin<'a>
impl<'a> Send for Plugin<'a>
impl<'a> Sync for Plugin<'a>
impl<'a> Unpin for Plugin<'a>
impl<'a> UnwindSafe for Plugin<'a>
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
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>
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>
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