pub enum HookType {
TaskPanic(Option<isize>, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>),
RequestError(Option<isize>, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>),
RequestMiddleware(Option<isize>, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>),
Route(&'static str, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>),
ResponseMiddleware(Option<isize>, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>),
}Expand description
Represents different types of hooks in the server lifecycle.
Each variant corresponds to a specific hook that can be registered
and triggered at different stages of request handling or server events.
Hooks with an Option<isize> allow specifying a priority order; None indicates
the default order (0 or unspecified).
Variants§
TaskPanic(Option<isize>, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)
Hook triggered when a task panic occurs during request processing.
Option<isize>- Optional execution priority. Higher values execute first.ServerHookHandlerFactory- Factory function creating the panic handler.
RequestError(Option<isize>, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)
Hook triggered when a request error occurs during HTTP request processing.
Option<isize>- Optional execution priority. Higher values execute first.ServerHookHandlerFactory- Factory function creating the error handler.
RequestMiddleware(Option<isize>, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)
Hook executed before a request reaches its designated route handler.
Option<isize>- Optional execution priority. Higher values execute first.ServerHookHandlerFactory- Factory function creating the middleware handler.
Route(&'static str, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)
Hook representing a route handler for a specific path.
&'static str- The route path pattern handled by this hook.ServerHookHandlerFactory- Factory function creating the route handler.
ResponseMiddleware(Option<isize>, fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)
Hook executed after a route handler but before the response is sent.
Option<isize>- Optional execution priority. Higher values execute first.ServerHookHandlerFactory- Factory function creating the middleware handler.
Implementations§
Source§impl HookType
Implementation block for HookType.
impl HookType
Implementation block for HookType.
This block defines utility methods associated with the HookType enum.
These methods provide additional functionality for working with hooks,
such as extracting the execution order (priority) used in duplicate checks.
Sourcepub fn try_get_order(&self) -> Option<isize>
pub fn try_get_order(&self) -> Option<isize>
Returns the optional execution priority (order) of a hook.
Hooks that carry an order indicate their execution priority.
Hooks without an order are considered unordered and are ignored in duplicate checks.
§Returns
Option<isize>-Some(order)if the hook defines a priority, otherwiseNone.
pub fn try_get_hook( &self, ) -> Option<fn() -> Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>>
Sourcepub fn assert_unique_order(list: Vec<HookType>)
pub fn assert_unique_order(list: Vec<HookType>)
Verifies that hooks with the same type and execution priority are unique.
This function validates that no two hooks of the same type have identical execution priorities (orders). Only hooks that define an explicit priority (non-None order) are checked for uniqueness. Hooks without a priority are ignored in duplicate detection.
§Arguments
Vec<HookType>- A vector ofHookTypeinstances to validate for uniqueness.
§Panics
- Panics if duplicate hooks are detected with the same type and priority, displaying the hook type and order in the error message.
Trait Implementations§
impl Collect for HookType
impl Copy for HookType
impl Eq for HookType
Implements the Eq trait for HookType.
This indicates that HookType has a total equality relation.
Source§impl Hash for HookType
Implements the Hash trait for HookType.
impl Hash for HookType
Implements the Hash trait for HookType.
This allows HookType to be used as a key in hash-based collections.
Function pointers are hashed using their addresses.