hyperlane/hook/type.rs
1use crate::*;
2
3/// A type alias for a shared hook handler.
4///
5/// This type is used for storing handlers in a shared context, allowing multiple
6/// parts of the application to safely access and execute the same handler.
7pub type HookHandler<T> = Arc<dyn FnContextPinBox<T>>;
8
9/// A type alias for a hook handler chain.
10///
11/// This type is used to represent a chain of middleware handlers that can be
12/// executed sequentially.
13pub type HookHandlerChain<T> = Vec<HookHandler<T>>;
14
15/// A type alias for a boxed future with a generic output that can be sent across threads.
16///
17/// This is often used to represent an asynchronous task that can be sent across threads.
18pub type FutureBox<T> = Pin<Box<dyn Future<Output = T> + Send>>;
19
20/// A type alias for a server control hook handler.
21///
22/// This type represents a thread-safe, reference-counted function that returns
23/// a boxed future when invoked. It is used for server lifecycle hooks such as
24/// graceful shutdown and wait operations.
25pub type ServerControlHookHandler<T> = Arc<dyn FutureFn<T>>;
26
27/// A type alias for a hook handler factory function.
28///
29/// This function pointer type is used to create ServerHookHandler instances
30/// based on generic types. It allows delayed instantiation of handlers.
31pub type ServerHookHandlerFactory = fn() -> ServerHookHandler;
32
33/// Type alias for a shared server hook handler.
34///
35/// This type allows storing handlers (route and middleware) of different concrete types
36/// in the same collection. The handler takes a `&mut Stream` and `&mut Context` and returns
37/// a pinned, boxed future that resolves to `Status`.
38pub type ServerHookHandler =
39 Arc<dyn Fn(&mut Stream, &mut Context) -> FutureBox<Status> + Send + Sync>;
40
41/// Type alias for a list of server hook handlers.
42///
43/// Used to store middleware handlers in the request/response processing pipeline.
44pub type ServerHookList = Vec<ServerHookHandler>;
45
46/// Type alias for a map of server route handlers.
47///
48/// Used for fast lookup of exact-match routes.
49pub type ServerHookMap = HashMapXxHash3_64<String, ServerHookHandler>;
50
51/// Type alias for a collection of pattern-based server hook route grouped by segment count.
52///
53/// The outer HashMap uses segment count as key for fast filtering.
54/// The inner Vec stores patterns with the same segment count, maintaining insertion order.
55pub type ServerHookPatternRoute = HashMapXxHash3_64<usize, Vec<(RoutePattern, ServerHookHandler)>>;