Trait Hook

Source
pub trait Hook:
    Send
    + Sync
    + 'static {
    type Args<'b>;
    type Result;

    // Required method
    fn call<'a>(
        &'a self,
        args: Self::Args<'a>,
        next: &dyn for<'c> Fn(Self::Args<'c>) -> Self::Result,
    ) -> Self::Result;
}
Expand description

A Trait for hooks. Implements this trait to create a hook.

Required Associated Types§

Source

type Args<'b>

The arguments type of the hook. Must be a tuple. Must be the same as the arguments of the target hookable function you want to hook.

Source

type Result

The result type of the hook. Must be the same as the result of the target hookable function.

Required Methods§

Source

fn call<'a>( &'a self, args: Self::Args<'a>, next: &dyn for<'c> Fn(Self::Args<'c>) -> Self::Result, ) -> Self::Result

The hook function. This will be called when the target function is called.

§Parameters:
  • args: The arguments of the target function.
  • next: The next function to call. This is the next hook or original target function.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§