Skip to main content

HookRegistry

Struct HookRegistry 

Source
pub struct HookRegistry { /* private fields */ }
Expand description

Central registry for all hooks.

Hooks are indexed by HookPoint for O(1) lookup. Within each point, hooks are sorted by priority (ascending).

§Concurrency

Use Arc<std::sync::RwLock<HookRegistry>> for concurrent access:

  • dispatch() takes &self (read lock)
  • register() / unregister() take &mut self (write lock)

Implementations§

Source§

impl HookRegistry

Source

pub fn new() -> Self

Creates an empty registry.

Source

pub fn register(&mut self, hook: Box<dyn Hook>) -> String

Registers a hook. Returns the hook’s ID.

The hook is inserted in priority order (ascending).

Source

pub fn register_owned( &mut self, hook: Box<dyn Hook>, owner: ComponentId, ) -> String

Registers a hook owned by a component.

Owned hooks are automatically unregistered when unregister_by_owner() is called (e.g., on component shutdown).

Source

pub fn unregister(&mut self, id: &str) -> bool

Unregisters a hook by ID. Returns true if found and removed.

Source

pub fn unregister_by_owner(&mut self, owner: &ComponentId) -> usize

Unregisters all hooks owned by the given component.

Returns the number of hooks removed.

Source

pub fn set_enabled(&mut self, id: &str, enabled: bool)

Enables or disables a hook by ID.

Source

pub fn len(&self) -> usize

Returns the number of registered hooks.

Source

pub fn is_empty(&self) -> bool

Returns true if no hooks are registered.

Source

pub fn dispatch( &self, point: HookPoint, component_id: &ComponentId, child_id: Option<&str>, ctx: HookContext, ) -> HookAction

Dispatches hooks for the given point and target.

Hooks are executed in priority order (ascending). Chain semantics:

  • Pre-hook: Skip or Abort → stop chain immediately
  • Post-hook: Replace → update payload, continue chain
  • Disabled hooks and FQL non-matches are skipped
  • Depth exceeded → break with warning

Trait Implementations§

Source§

impl Default for HookRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more