Skip to main content

PluginVTable

Struct PluginVTable 

Source
#[repr(C)]
pub struct PluginVTable { pub api_version: u32, pub create: extern "C" fn() -> RResult<*mut c_void, RBoxError>, pub destroy: extern "C" fn(state: *mut c_void), pub init: extern "C" fn(state: *mut c_void, ctx: &PluginContext) -> RResult<(), RBoxError>, pub process: extern "C" fn(state: *const c_void, msg: &SpoeMessage) -> RResult<ProcessingResult, RBoxError>, pub name: extern "C" fn(state: *const c_void) -> RStr<'static>, pub plugin_version: extern "C" fn(state: *const c_void) -> RStr<'static>, pub shutdown: extern "C" fn(state: *const c_void), pub config_schema: extern "C" fn(state: *const c_void) -> ROption<RString>, pub validate: extern "C" fn(state: *const c_void, ctx: &PluginContext) -> RVec<Diagnostic>, pub set_metric_recorder: extern "C" fn(state: *mut c_void, record_fn: RecordMetricFn, ctx: *const c_void), pub drain: extern "C" fn(state: *const c_void, timeout_ms: u64) -> bool, }
Expand description

The function table a plugin shared library exports.

#[repr(C)] is mandatory: it pins field offsets and padding rules so plugins built against an older version of this crate keep working when the hub is built against a newer one (and vice versa).

§Safety contract for hosts

Fields below the v1 baseline marker are version-gated. Hosts MUST NOT access them via &PluginVTable directly — the borrow would implicitly cover the whole struct, which on an older plugin is past the end of its allocation. Use the read_*_field accessors or read individual fields through the raw pointer (e.g. unsafe { (*ptr).api_version }) which read only the bytes for that field.

Fields§

§api_version: u32

Plugin’s reported API version. The hub uses this to gate access to fields beyond the v1 baseline.

§create: extern "C" fn() -> RResult<*mut c_void, RBoxError>

Factory: allocate and return a new plugin state pointer. RErr aborts plugin loading.

§destroy: extern "C" fn(state: *mut c_void)

Destructor: free the plugin state pointer. Called once at hub shutdown or when a plugin fails post-create. MUST tolerate being called with a state pointer that init() has not yet observed.

§init: extern "C" fn(state: *mut c_void, ctx: &PluginContext) -> RResult<(), RBoxError>

Initialize the plugin. Called once after create and any schema/validate pre-checks. RErr aborts plugin loading.

§process: extern "C" fn(state: *const c_void, msg: &SpoeMessage) -> RResult<ProcessingResult, RBoxError>

Handle one SPOE message. Called per request. The implementation is wrapped in catch_unwind by the define_plugin! macro so a panic does not abort the hub process.

§name: extern "C" fn(state: *const c_void) -> RStr<'static>

Plugin’s display name. Borrowed for the lifetime of the plugin instance (until destroy is called). Plugins typically return a &'static str literal.

§plugin_version: extern "C" fn(state: *const c_void) -> RStr<'static>

Plugin’s SemVer string. Same lifetime contract as name.

§shutdown: extern "C" fn(state: *const c_void)

Shutdown hook. Called once before destroy.

§config_schema: extern "C" fn(state: *const c_void) -> ROption<RString>

Optional JSON Schema string for config validation. RNone skips schema validation. The default define_plugin! macro emits a thunk that returns RNone when the plugin author has not declared one.

§validate: extern "C" fn(state: *const c_void, ctx: &PluginContext) -> RVec<Diagnostic>

Deep config validation. Returns an empty RVec when the plugin’s config is valid. Errors block loading; warnings are surfaced but do not block.

§set_metric_recorder: extern "C" fn(state: *mut c_void, record_fn: RecordMetricFn, ctx: *const c_void)

Install the hub’s metric recorder on the plugin. Called by the hub once between create and init, so the plugin can emit metrics from init onward. The plugin stores the record_fn and ctx (typically inside a MetricRecorder field of its state) and invokes record_fn(ctx, ...) for every metric event. The recorder remains valid until destroy returns; the hub guarantees lifetime, the plugin guarantees not to call it after destroy.

Plugins that don’t want metrics still need to provide a thunk (the define_plugin! macro emits a no-op default) — the field is unconditionally read on v2 hubs.

Host access: gated on api_version >= PLUGIN_API_VERSION_V2. Reading this field on a v1 plugin’s vtable is UB — the v1 allocation does not include these bytes.

§drain: extern "C" fn(state: *const c_void, timeout_ms: u64) -> bool

Block until the plugin’s in-flight background work has completed or timeout_ms milliseconds have elapsed. Called by the hub on a config reload between the registry swap and the call to shutdown, so plugins with fire-and-forget tasks (mirror’s runtime.spawn’d HTTP dispatches; otel’s batched exporter queue) can finish ACK’d requests before their runtime is torn down.

Returns true if the plugin reports it has nothing more in flight (clean drain). Returns false if the timeout elapsed while in-flight work was still pending (forced shutdown — the hub will still proceed with shutdown, the open requests are lost). Plugins MUST treat the timeout as advisory — going over is acceptable in narrow margins, but the hub’s overall reload SLO depends on drain respecting the deadline.

process() calls landing on this plugin instance AFTER drain is invoked are still serviced; the hub’s swap happens before drain, so post-swap traffic goes to the NEW registry. Drain concerns only work already in flight against this (now-old) instance.

Plugins with no background state (synchronous handlers that complete inside process()) get the define_plugin! macro’s default thunk which returns true immediately — nothing to wait for. Plugins that spawn background tasks SHOULD override drain to wait on their in-flight counter.

Host access: gated on api_version >= PLUGIN_API_VERSION_V3. Reading this field on a v1 or v2 plugin’s vtable is UB — those allocations do not include these bytes. The hub treats older plugins as “drained immediately” because those plugins have no in-flight background state in practice (coraza, external-auth, fingerprinting, maxmind, otel pre-v0.4, sso-auth all complete their work inside process()).

Implementations§

Source§

impl PluginVTable

Source

pub unsafe fn read_api_version(vtable_ptr: *const PluginVTable) -> u32

Read just the api_version field of a plugin’s vtable.

§Safety

vtable_ptr must be a non-null pointer to a PluginVTable allocation that is at least 4 bytes long (every plugin has at least the api_version field).

Source

pub unsafe fn read_set_metric_recorder( vtable_ptr: *const PluginVTable, ) -> Option<extern "C" fn(state: *mut c_void, record_fn: RecordMetricFn, ctx: *const c_void)>

Read the v2 set_metric_recorder field, returning None for plugins built against v1 (whose allocation doesn’t include it).

§Safety

vtable_ptr must be a non-null pointer to a PluginVTable allocation produced by a published plugin (i.e. consistent with the api_version field’s claim about which fields are present). On v1 plugins this function reads only api_version and returns None without touching past the v1 baseline.

Source

pub unsafe fn read_drain( vtable_ptr: *const PluginVTable, ) -> Option<extern "C" fn(state: *const c_void, timeout_ms: u64) -> bool>

Read the v3 drain field, returning None for plugins built against v1 or v2 (whose allocation doesn’t include it). The hub treats None as “drained immediately” — see the field’s doc comment for the rationale (older plugins are synchronous).

§Safety

vtable_ptr must be a non-null pointer to a PluginVTable allocation produced by a published plugin (i.e. consistent with the api_version field’s claim about which fields are present). On v1/v2 plugins this function reads only api_version and returns None without touching past the relevant baseline.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AlignerFor<1> for T

Source§

type Aligner = AlignTo1<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<1024> for T

Source§

type Aligner = AlignTo1024<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<128> for T

Source§

type Aligner = AlignTo128<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<16> for T

Source§

type Aligner = AlignTo16<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<16384> for T

Source§

type Aligner = AlignTo16384<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<2> for T

Source§

type Aligner = AlignTo2<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<2048> for T

Source§

type Aligner = AlignTo2048<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<256> for T

Source§

type Aligner = AlignTo256<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<32> for T

Source§

type Aligner = AlignTo32<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<32768> for T

Source§

type Aligner = AlignTo32768<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<4> for T

Source§

type Aligner = AlignTo4<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<4096> for T

Source§

type Aligner = AlignTo4096<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<512> for T

Source§

type Aligner = AlignTo512<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<64> for T

Source§

type Aligner = AlignTo64<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<8> for T

Source§

type Aligner = AlignTo8<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<8192> for T

Source§

type Aligner = AlignTo8192<T>

The AlignTo* type which aligns Self to ALIGNMENT.
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, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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<S> ROExtAcc for S

Source§

fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F

Gets a reference to a field, determined by offset. Read more
Source§

fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F

Gets a muatble reference to a field, determined by offset. Read more
Source§

fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F

Gets a const pointer to a field, the field is determined by offset. Read more
Source§

fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F

Gets a mutable pointer to a field, determined by offset. Read more
Source§

impl<S> ROExtOps<Aligned> for S

Source§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more
Source§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Aligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
Source§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> F
where F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
Source§

impl<S> ROExtOps<Unaligned> for S

Source§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more
Source§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
Source§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> F
where F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
Source§

impl<T> SelfOps for T
where T: ?Sized,

Source§

fn eq_id(&self, other: &Self) -> bool

Compares the address of self with the address of other. Read more
Source§

fn piped<F, U>(self, f: F) -> U
where F: FnOnce(Self) -> U, Self: Sized,

Emulates the pipeline operator, allowing method syntax in more places. Read more
Source§

fn piped_ref<'a, F, U>(&'a self, f: F) -> U
where F: FnOnce(&'a Self) -> U,

The same as piped except that the function takes &Self Useful for functions that take &Self instead of Self. Read more
Source§

fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U
where F: FnOnce(&'a mut Self) -> U,

The same as piped, except that the function takes &mut Self. Useful for functions that take &mut Self instead of Self.
Source§

fn mutated<F>(self, f: F) -> Self
where F: FnOnce(&mut Self), Self: Sized,

Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Source§

fn observe<F>(self, f: F) -> Self
where F: FnOnce(&Self), Self: Sized,

Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Source§

fn into_<T>(self) -> T
where Self: Into<T>,

Performs a conversion with Into. using the turbofish .into_::<_>() syntax. Read more
Source§

fn as_ref_<T>(&self) -> &T
where Self: AsRef<T>, T: ?Sized,

Performs a reference to reference conversion with AsRef, using the turbofish .as_ref_::<_>() syntax. Read more
Source§

fn as_mut_<T>(&mut self) -> &mut T
where Self: AsMut<T>, T: ?Sized,

Performs a mutable reference to mutable reference conversion with AsMut, using the turbofish .as_mut_::<_>() syntax. Read more
Source§

fn drop_(self)
where Self: Sized,

Drops self using method notation. Alternative to std::mem::drop. Read more
Source§

impl<This> TransmuteElement for This
where This: ?Sized,

Source§

unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr
where Self: CanTransmuteElement<T>,

Transmutes the element type of this pointer.. 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.
Source§

impl<T> TypeIdentity for T
where T: ?Sized,

Source§

type Type = T

This is always Self.
Source§

fn into_type(self) -> Self::Type
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
Source§

fn as_type(&self) -> &Self::Type

Converts a reference back to the original type.
Source§

fn as_type_mut(&mut self) -> &mut Self::Type

Converts a mutable reference back to the original type.
Source§

fn into_type_box(self: Box<Self>) -> Box<Self::Type>

Converts a box back to the original type.
Source§

fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>

Converts an Arc back to the original type. Read more
Source§

fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>

Converts an Rc back to the original type. Read more
Source§

fn from_type(this: Self::Type) -> Self
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
Source§

fn from_type_ref(this: &Self::Type) -> &Self

Converts a reference back to the original type.
Source§

fn from_type_mut(this: &mut Self::Type) -> &mut Self

Converts a mutable reference back to the original type.
Source§

fn from_type_box(this: Box<Self::Type>) -> Box<Self>

Converts a box back to the original type.
Source§

fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>

Converts an Arc back to the original type.
Source§

fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>

Converts an Rc back to the original type.