Skip to main content

hyperlane_core/hook/
enum.rs

1use super::*;
2
3/// Represents different types of hooks in the server lifecycle.
4///
5/// Each variant corresponds to a specific hook that can be registered
6/// and triggered at different stages of request handling or server events.
7/// Hooks with an `Option<isize>` allow specifying a priority order; `None` indicates
8/// the default order (0 or unspecified).
9///
10/// The hooks run in the order of their priority, from the smallest to the
11/// largest, and a hook without a priority runs before every hook that has
12/// one.
13#[derive(Clone, Copy, Debug, DisplayDebug)]
14pub enum HookType {
15    /// Hook triggered when a task panic occurs during request processing.
16    ///
17    /// - `Option<isize>` - Optional execution priority. The smaller the value,
18    ///   the earlier the hook runs.
19    /// - `ServerHookHandlerFactory` - Factory function creating the panic handler.
20    TaskPanic(Option<isize>, ServerHookHandlerFactory),
21    /// Hook triggered when a request error occurs during HTTP request processing.
22    ///
23    /// - `Option<isize>` - Optional execution priority. The smaller the value,
24    ///   the earlier the hook runs.
25    /// - `ServerHookHandlerFactory` - Factory function creating the error handler.
26    RequestError(Option<isize>, ServerHookHandlerFactory),
27    /// Hook executed before a request reaches its designated route handler.
28    ///
29    /// - `Option<isize>` - Optional execution priority. The smaller the value,
30    ///   the earlier the hook runs.
31    /// - `ServerHookHandlerFactory` - Factory function creating the middleware handler.
32    RequestMiddleware(Option<isize>, ServerHookHandlerFactory),
33    /// Hook representing a route handler for a specific path.
34    ///
35    /// - `&'static str` - The route path pattern handled by this hook.
36    /// - `ServerHookHandlerFactory` - Factory function creating the route handler.
37    Route(&'static str, ServerHookHandlerFactory),
38    /// Hook executed after a route handler but before the response is sent.
39    ///
40    /// - `Option<isize>` - Optional execution priority. The smaller the value,
41    ///   the earlier the hook runs.
42    /// - `ServerHookHandlerFactory` - Factory function creating the middleware handler.
43    ResponseMiddleware(Option<isize>, ServerHookHandlerFactory),
44}