pub struct RouteMatcher {
pub static_route: HashMap<String, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>, BuildHasherDefault<Hasher>>,
pub dynamic_route: HashMap<usize, Vec<(RoutePattern, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)>, BuildHasherDefault<Hasher>>,
pub regex_route: HashMap<usize, Vec<(RoutePattern, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)>, BuildHasherDefault<Hasher>>,
}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: HashMap<String, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>, BuildHasherDefault<Hasher>>A hash map for storing and quickly retrieving handlers for static route. These are route without any variable path segments.
dynamic_route: HashMap<usize, Vec<(RoutePattern, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)>, BuildHasherDefault<Hasher>>A layered map of dynamic routes grouped by segment count. Routes are organized by path segment count for efficient filtering during matching.
regex_route: HashMap<usize, Vec<(RoutePattern, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)>, BuildHasherDefault<Hasher>>A 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 Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>>
pub fn try_resolve_route<'a>( &'a self, ctx: &mut Context, path: &str, ) -> Option<&'a Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>>
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, ) -> &HashMap<String, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>, BuildHasherDefault<Hasher>>
pub fn get_mut_static_route( &mut self, ) -> &mut HashMap<String, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>, BuildHasherDefault<Hasher>>
pub fn get_dynamic_route( &self, ) -> &HashMap<usize, Vec<(RoutePattern, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)>, BuildHasherDefault<Hasher>>
pub fn get_mut_dynamic_route( &mut self, ) -> &mut HashMap<usize, Vec<(RoutePattern, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)>, BuildHasherDefault<Hasher>>
pub fn get_regex_route( &self, ) -> &HashMap<usize, Vec<(RoutePattern, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)>, BuildHasherDefault<Hasher>>
pub fn get_mut_regex_route( &mut self, ) -> &mut HashMap<usize, Vec<(RoutePattern, Arc<dyn Fn(&mut Stream, &mut Context) -> Pin<Box<dyn Future<Output = Status> + Send>> + Send + Sync>)>, BuildHasherDefault<Hasher>>
Trait Implementations§
Source§impl Clone for RouteMatcher
impl Clone for RouteMatcher
Source§fn clone(&self) -> RouteMatcher
fn clone(&self) -> RouteMatcher
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for RouteMatcher
Provides a default implementation for RouteMatcher.
impl Default for RouteMatcher
Provides a default implementation for RouteMatcher.
Source§fn default() -> RouteMatcher
fn default() -> RouteMatcher
Creates a new, empty RouteMatcher.
§Returns
RouteMatcher- A new RouteMatcher with empty storage for static, dynamic, and regex route.
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.
Source§impl PartialEq for RouteMatcher
Implements the PartialEq trait for RouteMatcher.
impl PartialEq for RouteMatcher
Implements the PartialEq trait for RouteMatcher.
This allows for comparing two RouteMatcher instances for equality.
Source§fn eq(&self, other: &RouteMatcher) -> bool
fn eq(&self, other: &RouteMatcher) -> bool
Auto Trait Implementations§
impl !RefUnwindSafe for RouteMatcher
impl !UnwindSafe for RouteMatcher
impl Forget 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.