Skip to main content

LifecycleHook

Trait LifecycleHook 

Source
pub trait LifecycleHook: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn before_operation<'a>(
        &'a self,
        context: &'a mut HookContext<'_>,
    ) -> HookFuture<'a, Result<PreHookResult, HookError>>;
    fn after_operation<'a>(
        &'a self,
        context: &'a HookContext<'_>,
    ) -> HookFuture<'a, Result<(), HookError>>;

    // Provided method
    fn should_run(&self, context: &HookContext<'_>) -> bool { ... }
}
Expand description

Object-safe lifecycle hook for an exact generated entity or relation.

Required Methods§

Source

fn name(&self) -> &str

Stable application-owned hook name used in diagnostics.

Source

fn before_operation<'a>( &'a self, context: &'a mut HookContext<'_>, ) -> HookFuture<'a, Result<PreHookResult, HookError>>

Run before database work. Return PreHookResult::Reject to cancel.

Source

fn after_operation<'a>( &'a self, context: &'a HookContext<'_>, ) -> HookFuture<'a, Result<(), HookError>>

Run after a successful commit. Errors are logged and not propagated.

Provided Methods§

Source

fn should_run(&self, context: &HookContext<'_>) -> bool

Return false to skip this hook for one context.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§