Skip to main content

Hook

Trait Hook 

Source
pub trait Hook:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn before(
        &self,
        _event: &Event<'_>,
        _ctx: &Context,
    ) -> Result<(), JsonApiError> { ... }
    fn after(&self, _event: &Event<'_>, _outcome: &Outcome, _ctx: &Context) { ... }
}
Expand description

Something that runs around every operation.

Both methods have a default that does nothing, so a hook implements only the half it cares about: an audit sink is an after, an authorization check is a before.

Provided Methods§

Source

fn before(&self, _event: &Event<'_>, _ctx: &Context) -> Result<(), JsonApiError>

Runs before the operation. An Err refuses the request, and the operation never runs.

This is where authorization belongs: a denial that reaches storage has already leaked whether the row exists.

Source

fn after(&self, _event: &Event<'_>, _outcome: &Outcome, _ctx: &Context)

Runs after the operation, whatever happened.

Cannot change the response — recording must not be able to break a request that otherwise worked.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Hook for Audit

Available on crate feature audit only.