pub struct Hooks { /* private fields */ }Expand description
Per-command hook configuration.
Hooks are registered per-command path and executed in order.
Implementations§
Source§impl Hooks
impl Hooks
Sourcepub fn pre_dispatch<F>(self, f: F) -> Self
pub fn pre_dispatch<F>(self, f: F) -> Self
Adds a pre-dispatch hook.
Pre-dispatch hooks receive mutable access to CommandContext, allowing
state injection via ctx.extensions. Handlers can then retrieve this state.
§Example
use standout_dispatch::{Hooks, HookError};
struct ApiClient { base_url: String }
let hooks = Hooks::new()
.pre_dispatch(|_matches, ctx| {
ctx.extensions.insert(ApiClient {
base_url: "https://api.example.com".into()
});
Ok(())
});Sourcepub fn post_dispatch<F>(self, f: F) -> Selfwhere
F: Fn(&ArgMatches, &CommandContext, Value) -> Result<Value, HookError> + Send + Sync + 'static,
pub fn post_dispatch<F>(self, f: F) -> Selfwhere
F: Fn(&ArgMatches, &CommandContext, Value) -> Result<Value, HookError> + Send + Sync + 'static,
Adds a post-dispatch hook.
Sourcepub fn post_output<F>(self, f: F) -> Selfwhere
F: Fn(&ArgMatches, &CommandContext, RenderedOutput) -> Result<RenderedOutput, HookError> + Send + Sync + 'static,
pub fn post_output<F>(self, f: F) -> Selfwhere
F: Fn(&ArgMatches, &CommandContext, RenderedOutput) -> Result<RenderedOutput, HookError> + Send + Sync + 'static,
Adds a post-output hook.
Sourcepub fn run_pre_dispatch(
&self,
matches: &ArgMatches,
ctx: &mut CommandContext,
) -> Result<(), HookError>
pub fn run_pre_dispatch( &self, matches: &ArgMatches, ctx: &mut CommandContext, ) -> Result<(), HookError>
Runs all pre-dispatch hooks.
Hooks receive mutable access to the context, allowing state injection.
Sourcepub fn run_post_dispatch(
&self,
matches: &ArgMatches,
ctx: &CommandContext,
data: Value,
) -> Result<Value, HookError>
pub fn run_post_dispatch( &self, matches: &ArgMatches, ctx: &CommandContext, data: Value, ) -> Result<Value, HookError>
Runs all post-dispatch hooks, chaining transformations.
Sourcepub fn run_post_output(
&self,
matches: &ArgMatches,
ctx: &CommandContext,
output: RenderedOutput,
) -> Result<RenderedOutput, HookError>
pub fn run_post_output( &self, matches: &ArgMatches, ctx: &CommandContext, output: RenderedOutput, ) -> Result<RenderedOutput, HookError>
Runs all post-output hooks, chaining transformations.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Hooks
impl !RefUnwindSafe for Hooks
impl Send for Hooks
impl Sync for Hooks
impl Unpin for Hooks
impl !UnwindSafe for Hooks
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