hyperlane-core 23.4.0

A lightweight, high-performance, and cross-platform Rust HTTP server library built on Tokio. It simplifies modern web service development by providing built-in support for middleware, WebSocket, Server-Sent Events (SSE), and raw TCP communication. With a unified and ergonomic API across Windows, Linux, and MacOS, it enables developers to build robust, scalable, and event-driven network applications with minimal overhead and maximum flexibility.
Documentation
use super::*;

/// Unregisters a [`Hook::factory`] inline initializer when its handler `Arc` is dropped.
pub(crate) struct InlineHookGuard {
    /// Pointer address of the enclosing [`ServerHookHandler`] `Arc` payload.
    pub(crate) key: Arc<AtomicUsize>,
}

/// Panic-safe drop guard for an in-place inline future being polled for the first time.
pub(crate) struct InlineDropGuard<F> {
    /// Raw pointer to the initialized future in inline storage.
    pub(crate) ptr: *mut F,
}

/// Node inside a compiled segment-based [`RouteTrie`] preserving `Static > Dynamic > Regex` order.
#[derive(Clone, Default)]
pub(crate) struct RouteTrieNode {
    /// Small flat list of `(literal, child_idx)` edges scanned linearly without hashing.
    pub(super) small_static: Vec<(String, usize)>,
    /// Hash map of `(literal -> child_idx)` used when a node has more than [`SMALL_TRIE_STATIC_LIMIT`] static edges.
    pub(super) static_map: HashMapXxHash3_64<String, usize>,
    /// Dynamic parameter child edges `(param_name, child_idx)` in deterministic pattern order.
    pub(super) dynamic_children: Vec<(String, usize)>,
    /// Regex segment child edges `(param_name, compiled_regex, child_idx)` in deterministic pattern order.
    pub(super) regex_children: Vec<(String, Regex, usize)>,
    /// Terminal route hook stored when a pattern ends at this node.
    pub(super) leaf: Option<CompiledHook>,
}

/// Compact arena-backed segment trie for O(depth) dynamic and regex route dispatch.
#[derive(Clone, Default)]
pub(crate) struct RouteTrie {
    /// Arena of trie nodes; index `0` is the root when non-empty.
    pub(super) nodes: Vec<RouteTrieNode>,
}

/// Unified single-slot stack-pinned future driving request middleware, route, and response middleware.
pub(crate) struct InlineRequestFuture<'a> {
    /// Compiled pipeline dispatch table.
    pub(super) pipeline: &'a CompiledPipeline,
    /// The active connection stream.
    pub(super) stream: &'a mut Stream,
    /// The active request context.
    pub(super) ctx: &'a mut Context,
    /// Current pipeline execution phase.
    pub(super) phase: InlinePipelinePhase,
    /// Next hook index within the active middleware slice.
    pub(super) index: usize,
    /// Whether the incoming request allowed keep-alive.
    pub(super) keep_alive: bool,
    /// Whether response keep-alive inspection is required (HTTP/1.x only).
    pub(super) check_keep_alive: bool,
    /// Lifecycle state of the currently suspended hook future, if any.
    pub(super) state: InlinePollState,
    /// Single aligned inline storage slot reused across all three pipeline phases.
    pub(super) storage: MaybeUninit<[usize; INLINE_FUTURE_WORDS]>,
    /// Prevents moving the future after pinning.
    pub(super) _pinned: PhantomPinned,
}

/// Immutable per-server dispatch table compiled once when [`Server::run`] starts.
#[derive(Clone)]
pub(crate) struct CompiledPipeline {
    /// Small static route table scanned linearly without hashing when route count is small.
    pub(super) small_static_routes: SmallStaticRoutes,
    /// Static exact-match routes used when route count exceeds [`SMALL_STATIC_ROUTE_LIMIT`].
    pub(super) static_routes: HashMapXxHash3_64<String, CompiledHook>,
    /// Minimum byte length among registered static route paths (`usize::MAX` when empty).
    pub(super) min_static_len: usize,
    /// Maximum byte length among registered static route paths (`0` when empty).
    pub(super) max_static_len: usize,
    /// Dynamic parameter route tries indexed directly by segment count.
    pub(super) dynamic_tries: CompiledRouteTries,
    /// Whether any dynamic routes are registered.
    pub(super) has_dynamic: bool,
    /// Exact-segment-count regex route tries indexed directly by segment count.
    pub(super) regex_tries: CompiledRouteTries,
    /// Tail-regex routes that can match paths with equal or more segments.
    pub(super) regex_tail_routes: CompiledTailRegexRoutes,
    /// Whether any regex routes are registered.
    pub(super) has_regex: bool,
    /// Request middleware chain in registration order.
    pub(super) request_middleware: Vec<CompiledHook>,
    /// Response middleware chain in registration order.
    pub(super) response_middleware: Vec<CompiledHook>,
}