hyperlane-core 23.3.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,
}

/// Stack-pinned future that runs a [`ServerHook`] inline without heap allocation when it fits.
pub(crate) struct InlineHookCall<'a> {
    /// The stream passed to the hook.
    pub(super) stream: &'a mut Stream,
    /// The request context passed to the hook.
    pub(super) ctx: &'a mut Context,
    /// Monomorphized fused starter for the concrete hook type.
    pub(super) start: InlineStartFn,
    /// Current lifecycle state of the future in `storage`.
    pub(super) state: InlinePollState,
    /// Aligned inline storage for the pinned hook future.
    pub(super) storage: MaybeUninit<[usize; INLINE_FUTURE_WORDS]>,
    /// Prevents moving the future after pinning.
    pub(super) _pinned: PhantomPinned,
}

/// Stack-pinned future that executes a slice of [`CompiledHook`] entries in a tight loop.
pub(crate) struct InlineHookChain<'a> {
    /// The stream passed to each hook.
    pub(super) stream: &'a mut Stream,
    /// The request context passed to each hook.
    pub(super) ctx: &'a mut Context,
    /// Slice of compiled middleware hooks to execute in registration order.
    pub(super) hooks: &'a [CompiledHook],
    /// Next hook index to invoke when no active hook future is pending.
    pub(super) index: usize,
    /// Current lifecycle state of the active pending hook future, if any.
    pub(super) state: InlinePollState,
    /// Aligned inline storage for a pending pinned hook future.
    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 routes indexed directly by segment count.
    pub(super) dynamic_routes: CompiledPatternBuckets,
    /// Whether any dynamic routes are registered.
    pub(super) has_dynamic: bool,
    /// Regex routes indexed directly by segment count.
    pub(super) regex_routes: CompiledPatternBuckets,
    /// 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>,
}