pub trait PluginPayload:
Send
+ Sync
+ 'static {
// Required methods
fn clone_boxed(&self) -> Box<dyn PluginPayload>;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}Expand description
Base trait for all hook payloads.
Mirrors Python’s PluginPayload(BaseModel, frozen=True). Every
payload type in the framework implements this trait. The executor
and registry use Box<dyn PluginPayload> (not Box<dyn Any>)
for type-safe dispatch.
The trait is object-safe — it can be used behind Box, &,
and Arc without knowing the concrete type. This is achieved by
providing clone_boxed() instead of requiring Clone directly
(which is not object-safe), and as_any() / as_any_mut() for
downcasting to the concrete type when needed.
Payloads are:
- Cloneable via
clone_boxed()— the executor uses this for COW when a modifying plugin (Sequential or Transform) needs ownership. Send + Sync— payloads may be shared across threads for Concurrent mode plugins.'static— payloads must be owned types (no borrowed references).
Extensions are not part of the payload. They are passed as a
separate &Extensions parameter to handlers.
§Examples
use cpex_core::hooks::payload::PluginPayload;
#[derive(Debug, Clone)]
struct RateLimitPayload {
client_id: String,
request_count: u64,
}
impl PluginPayload for RateLimitPayload {
fn clone_boxed(&self) -> Box<dyn PluginPayload> {
Box::new(self.clone())
}
fn as_any(&self) -> &dyn std::any::Any { self }
fn as_any_mut(&mut self) -> &mut dyn std::any::Any { self }
}Required Methods§
Sourcefn clone_boxed(&self) -> Box<dyn PluginPayload>
fn clone_boxed(&self) -> Box<dyn PluginPayload>
Clone this payload into a new Box<dyn PluginPayload>.
Used by the executor for copy-on-write: read-only modes borrow the payload, modifying modes receive a clone via this method.
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Downcast to a concrete type via &dyn Any.
Used by typed handler wrappers to recover the concrete payload
type from Box<dyn PluginPayload>.
Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Downcast to a concrete type via &mut dyn Any.
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".