Struct Plugin

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

Source

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();
Source

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

pub fn init(&self) -> bool

Execute plugin’s initialization routine. Returns true if the route exists and was executed, false otherwise.

Source

pub fn fini(&self)

Execute plugin’s shutdown routine.

Source

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

pub fn name(&self) -> &str

Returns plugin’s name. This is the same name as what is passed to Plugin::load function.

Source

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.

Source

pub fn version(&self) -> Option<PdStr>

Get plugin version. It’s set in plugin’s Cargo.toml.

Trait Implementations§

Source§

impl<'a> Debug for Plugin<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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, 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.