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 pub(super) RouteSegmentList,
12);
13
14/// The core routing engine responsible for matching request paths to their corresponding handlers.
15///
16/// The matcher categorizes route into three types for optimized performance:
17/// 1. `static_route` - For exact path matches, offering the fastest lookups.
18/// 2. `dynamic_route` - For paths with variable segments.
19/// 3. `regex_route` - For complex matching based on regular expressions.
20///
21/// When a request comes in, the matcher checks these categories in order to find the appropriate hook.
22#[derive(Clone, CustomDebug, DisplayDebug, Getter, GetterMut, Setter)]
23pub struct RouteMatcher {
24 /// A hash map for storing and quickly retrieving handlers for static route.
25 /// These are route without any variable path segments.
26 #[set(skip)]
27 #[debug(skip)]
28 pub(super) static_route: ServerHookMap,
29 /// A layered map of dynamic routes grouped by segment count.
30 /// Routes are organized by path segment count for efficient filtering during matching.
31 #[set(skip)]
32 #[debug(skip)]
33 pub(super) dynamic_route: ServerHookPatternRoute,
34 /// A layered map of regex routes grouped by segment count.
35 /// Routes with tail regex patterns can match paths with more segments.
36 #[set(skip)]
37 #[debug(skip)]
38 pub(super) regex_route: ServerHookPatternRoute,
39}