hyperlane/route/
struct.rs

1use crate::*;
2
3/// Represents a parsed and structured route pattern.
4///
5/// This struct wraps a vector of `RouteSegment`s, which are the individual components
6/// of a URL path. It is used internally by the `RouteMatcher` to perform efficient
7/// route matching against incoming requests.
8#[derive(Debug, Clone, Getter, DisplayDebug)]
9pub struct RoutePattern(
10    /// The collection of segments that make up the route pattern.
11    #[get]
12    pub(super) RouteSegmentList,
13);
14
15/// The core routing engine responsible for matching request paths to their corresponding handlers.
16///
17/// The matcher categorizes route into three types for optimized performance:
18/// 1.  `static_route`- For exact path matches, offering the fastest lookups.
19/// 2.  `dynamic_route`- For paths with variable segments.
20/// 3.  `regex_route`- For complex matching based on regular expressions.
21///
22/// When a request comes in, the matcher checks these categories in order to find the appropriate handler.
23#[derive(Clone, CustomDebug, Getter, GetterMut, DisplayDebug, Setter)]
24pub struct RouteMatcher {
25    /// A hash map for storing and quickly retrieving handlers for static route.
26    /// These are route without any variable path segments.
27    #[get]
28    #[set(skip)]
29    #[get_mut(pub(super))]
30    #[debug(skip)]
31    pub(super) static_route: ServerHookMap,
32    /// A layered map of dynamic routes grouped by segment count.
33    /// Routes are organized by path segment count for efficient filtering during matching.
34    #[get]
35    #[set(skip)]
36    #[get_mut(pub(super))]
37    #[debug(skip)]
38    pub(super) dynamic_route: ServerHookPatternRoute,
39    /// A layered map of regex routes grouped by segment count.
40    /// Routes with tail regex patterns can match paths with more segments.
41    #[get]
42    #[set(skip)]
43    #[get_mut(pub(super))]
44    #[debug(skip)]
45    pub(super) regex_route: ServerHookPatternRoute,
46    /// AC automaton for fast dynamic/regex route static segment matching.
47    /// Used to quickly filter candidate routes by matching static segments.
48    #[get]
49    #[set(pub(super))]
50    #[debug(skip)]
51    pub(super) ac_automaton: OptionRouteSearchEngine,
52    /// Static segment patterns extracted from dynamic/regex routes for AC automaton.
53    /// Maps pattern_idx to (segment_count, route_index, is_regex).
54    #[get]
55    #[set(pub(super))]
56    #[debug(skip)]
57    pub(super) ac_pattern_map: HashMapXxHash3_64<usize, (usize, usize, bool)>,
58}