pub struct HookChain { /* private fields */ }Expand description
Ordered set of hooks subscribed to a single event. The hooks are
sorted by priority descending at construction time; ties keep
their hooks.toml insertion order (Vec::sort_by is stable, so
feeding it a load-order vec gives the documented behaviour for
free).
The chain runner is a method on the chain rather than a free
function so callers can hold a chain across multiple fires
(e.g. one per event tag, built once on hooks.toml load and
reused across many request paths).
Implementations§
Source§impl HookChain
impl HookChain
Sourcepub fn for_event(all_hooks: &[HookConfig], event: HookEvent) -> Self
pub fn for_event(all_hooks: &[HookConfig], event: HookEvent) -> Self
Build a chain from the hooks subscribed to event. The input
vec is filtered to enabled entries matching event and then
sorted by priority descending.
Insertion order from hooks.toml is the secondary sort key
(i.e. ties break in load order). Vec::sort_by is stable so
no extra bookkeeping is needed — a load-order input gives the
documented behaviour.
Sourcepub fn new(hooks: Vec<HookConfig>) -> Self
pub fn new(hooks: Vec<HookConfig>) -> Self
Construct from an explicit, pre-filtered hook list. The list
is still priority-sorted on the way in. Used by tests that
want to bypass the enabled / event filter.
Sourcepub fn hooks(&self) -> &[HookConfig]
pub fn hooks(&self) -> &[HookConfig]
Returns the priority-sorted hook list. Useful for tests (asserting the ordering pass landed) and for the doctor surface (rendering the configured chain).
Sourcepub async fn fire(
&self,
event: HookEvent,
payload: Value,
registry: &mut ExecutorRegistry,
) -> ChainResult
pub async fn fire( &self, event: HookEvent, payload: Value, registry: &mut ExecutorRegistry, ) -> ChainResult
Run the chain. Iterates hooks in priority order, threads the
possibly-mutated payload through, and short-circuits on the
first Deny.
registry is taken &mut because ExecutorRegistry::get
inserts on cache miss. Once every hook in the chain has been
fired at least once the registry is steady-state and a fully
pre-warmed registry built via ExecutorRegistry::from_hooks
makes this a read-only path.
The future is async because each hook’s fire is async;
the chain itself does no extra work between fires beyond the
in-memory delta merge.
Auto Trait Implementations§
impl Freeze for HookChain
impl RefUnwindSafe for HookChain
impl Send for HookChain
impl Sync for HookChain
impl Unpin for HookChain
impl UnsafeUnpin for HookChain
impl UnwindSafe for HookChain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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