pub struct HookManager { /* private fields */ }Expand description
Manages a collection of hooks and executes them in order.
Hooks are executed in priority order (lower priority runs first). If any hook returns Skip, SkipWith, or Abort, execution stops.
§Example
use liteforge::hooks::{Hook, HookContext, HookResult, HookManager, HookEvent};
struct LogHook;
impl Hook for LogHook {
fn name(&self) -> &str { "log" }
fn on_before_tool_call(&self, ctx: &HookContext) -> HookResult {
println!("Tool call: {:?}", ctx.data);
HookResult::Continue
}
}
let mut manager = HookManager::new();
manager.register(Box::new(LogHook));
let ctx = HookContext::new(HookEvent::BeforeToolCall);
let result = manager.run(&ctx);
assert!(result.should_continue());Implementations§
Source§impl HookManager
impl HookManager
Sourcepub fn unregister(&self, name: &str) -> bool
pub fn unregister(&self, name: &str) -> bool
Unregister a hook by name.
Returns true if a hook was removed.
Sourcepub fn run(&self, ctx: &HookContext) -> HookResult
pub fn run(&self, ctx: &HookContext) -> HookResult
Run all hooks for an event.
Hooks are executed in priority order. Execution stops if any hook returns Skip, SkipWith, or Abort.
Sourcepub fn run_mut(&self, ctx: &mut HookContext) -> HookResult
pub fn run_mut(&self, ctx: &mut HookContext) -> HookResult
Run hooks with mutable context, allowing hooks to modify data.
If a hook returns ContinueWith, the context data is updated before calling the next hook.
Sourcepub fn hook_names(&self) -> Vec<String>
pub fn hook_names(&self) -> Vec<String>
Get the names of all registered hooks.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for HookManager
impl RefUnwindSafe for HookManager
impl Send for HookManager
impl Sync for HookManager
impl Unpin for HookManager
impl UnsafeUnpin for HookManager
impl UnwindSafe for HookManager
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
Mutably borrows from an owned value. Read more