pub struct HookCallbackMatcher {
pub name: Option<String>,
pub matcher: Option<String>,
pub hooks: Vec<Arc<dyn Fn(HookInput, Option<String>, CancellationToken) -> Pin<Box<dyn Future<Output = Result<HookOutput, HookError>> + Send>> + Send + Sync>>,
pub timeout: Option<u64>,
pub requires: Option<HookRequirements>,
}Expand description
Hook configuration with optional regex matcher pattern.
Groups one or more callbacks with a regex filter. The matcher pattern is tested against the hook’s filter field (typically the tool name for tool-related hooks). If no matcher is set, the hooks run for every event of their type.
§Example
use starpod_hooks::{hook_fn, HookCallbackMatcher, HookOutput};
let matcher = HookCallbackMatcher::new(vec![
hook_fn(|_input, _id, _cancel| async move {
Ok(HookOutput::default())
}),
])
.with_matcher("Bash|Write")
.with_timeout(30);
assert!(matcher.matches("Bash").unwrap());
assert!(!matcher.matches("Read").unwrap());Fields§
§name: Option<String>Human-readable name for this hook group (used by circuit breaker and logging).
matcher: Option<String>Regex pattern to match against the event’s filter field (e.g., tool name). If None, the hook runs for every event of its type.
hooks: Vec<Arc<dyn Fn(HookInput, Option<String>, CancellationToken) -> Pin<Box<dyn Future<Output = Result<HookOutput, HookError>> + Send>> + Send + Sync>>Array of callback functions to execute when the pattern matches.
timeout: Option<u64>Timeout in seconds for all hooks in this matcher.
requires: Option<HookRequirements>Eligibility requirements (binaries, env vars, OS).
Implementations§
Source§impl HookCallbackMatcher
impl HookCallbackMatcher
pub fn new( hooks: Vec<Arc<dyn Fn(HookInput, Option<String>, CancellationToken) -> Pin<Box<dyn Future<Output = Result<HookOutput, HookError>> + Send>> + Send + Sync>>, ) -> HookCallbackMatcher
pub fn with_name(self, name: impl Into<String>) -> HookCallbackMatcher
pub fn with_matcher(self, matcher: impl Into<String>) -> HookCallbackMatcher
pub fn with_timeout(self, timeout: u64) -> HookCallbackMatcher
pub fn with_requirements( self, requires: HookRequirements, ) -> HookCallbackMatcher
Trait Implementations§
Source§impl Clone for HookCallbackMatcher
impl Clone for HookCallbackMatcher
Source§fn clone(&self) -> HookCallbackMatcher
fn clone(&self) -> HookCallbackMatcher
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HookCallbackMatcher
impl !RefUnwindSafe for HookCallbackMatcher
impl Send for HookCallbackMatcher
impl Sync for HookCallbackMatcher
impl Unpin for HookCallbackMatcher
impl UnsafeUnpin for HookCallbackMatcher
impl !UnwindSafe for HookCallbackMatcher
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.