pub struct RouteMatcher {
pub static_route: ServerHookMap,
pub dynamic_route: ServerHookPatternRoute,
pub regex_route: ServerHookPatternRoute,
}Expand description
The core routing engine responsible for matching request paths to their corresponding handlers.
The matcher categorizes route into three types for optimized performance:
static_route- For exact path matches, offering the fastest lookups.dynamic_route- For paths with variable segments.regex_route- For complex matching based on regular expressions.
When a request comes in, the matcher checks these categories in order to find the appropriate hook.
Fields§
§static_route: ServerHookMapA hash map for storing and quickly retrieving handlers for static route. These are route without any variable path segments.
dynamic_route: ServerHookPatternRouteA layered map of dynamic routes grouped by segment count. Routes are organized by path segment count for efficient filtering during matching.
regex_route: ServerHookPatternRouteA layered map of regex routes grouped by segment count. Routes with tail regex patterns can match paths with more segments.
Implementations§
Source§impl RouteMatcher
Manages a collection of route, enabling efficient lookup and dispatch.
impl RouteMatcher
Manages a collection of route, enabling efficient lookup and dispatch.
This struct stores route categorized by type (static, dynamic, regex) to quickly find the appropriate hook for incoming requests.
Sourcepub fn try_resolve_route<'a>(
&'a self,
ctx: &mut Context,
path: &str,
) -> Option<&'a ServerHookHandler>
pub fn try_resolve_route<'a>( &'a self, ctx: &mut Context, path: &str, ) -> Option<&'a ServerHookHandler>
Resolves a route hook by reference (no Arc::clone) for hot-path use.
Returns a reference to the matched ServerHookHandler if any. The
caller must clone if it needs to retain the hook beyond the await point.
Returns None if no route matched.
§Arguments
&'a self- The route table to search.&mut Context- The request context (for storing route params).&str- The request path to resolve.
§Returns
Option<&'a ServerHookHandler>: The matched handler, orNonewhen no route matched.
Source§impl RouteMatcher
impl RouteMatcher
pub fn get_static_route(&self) -> &ServerHookMap
pub fn get_mut_static_route(&mut self) -> &mut ServerHookMap
pub fn get_dynamic_route(&self) -> &ServerHookPatternRoute
pub fn get_mut_dynamic_route(&mut self) -> &mut ServerHookPatternRoute
pub fn get_regex_route(&self) -> &ServerHookPatternRoute
pub fn get_mut_regex_route(&mut self) -> &mut ServerHookPatternRoute
Trait Implementations§
Source§impl Clone for RouteMatcher
impl Clone for RouteMatcher
Source§impl Debug for RouteMatcher
impl Debug for RouteMatcher
Source§impl Default for RouteMatcher
Provides a default implementation for RouteMatcher.
impl Default for RouteMatcher
Provides a default implementation for RouteMatcher.
Source§impl Display for RouteMatcher
impl Display for RouteMatcher
impl Eq for RouteMatcher
Implements the Eq trait for RouteMatcher.
This indicates that RouteMatcher has a total equality relation.
Auto Trait Implementations§
impl !RefUnwindSafe for RouteMatcher
impl !UnwindSafe for RouteMatcher
impl Freeze for RouteMatcher
impl Send for RouteMatcher
impl Sync for RouteMatcher
impl Unpin for RouteMatcher
impl UnsafeUnpin for RouteMatcher
Blanket Implementations§
impl<T> AnySend for T
impl<T> AnySendClone for T
impl<T> AnySendSync for T
impl<T> AnySendSyncClone for T
impl<T> AnySync for T
impl<T> AnySyncClone for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.