hyperlane_core/route/struct.rs
1use super::*;
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(Clone, Debug, DisplayDebug, Getter)]
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 hook.
23#[derive(Clone, CustomDebug, DisplayDebug, Getter, GetterMut, 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 #[debug(skip)]
30 pub(super) static_route: ServerHookMap,
31 /// A layered map of dynamic routes grouped by segment count.
32 /// Routes are organized by path segment count for efficient filtering during matching.
33 #[get]
34 #[set(skip)]
35 #[debug(skip)]
36 pub(super) dynamic_route: ServerHookPatternRoute,
37 /// A layered map of regex routes grouped by segment count.
38 /// Routes with tail regex patterns can match paths with more segments.
39 #[get]
40 #[set(skip)]
41 #[debug(skip)]
42 pub(super) regex_route: ServerHookPatternRoute,
43}