pub trait IRouter: Send + Sync {
// Required methods
fn register(
&mut self,
method: HttpMethod,
path: &str,
endpoint: Arc<dyn IEndpoint>,
);
fn match_route<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut dyn IHttpContext,
) -> Pin<Box<dyn Future<Output = Result<Option<(Arc<dyn IEndpoint>, HashMap<String, String>, String)>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Router that matches incoming HTTP requests to registered endpoints.
Analogous to ASP.NET Core’s IRouter / EndpointRouting.
Required Methods§
Sourcefn register(
&mut self,
method: HttpMethod,
path: &str,
endpoint: Arc<dyn IEndpoint>,
)
fn register( &mut self, method: HttpMethod, path: &str, endpoint: Arc<dyn IEndpoint>, )
Register a new route with the router.
Sourcefn match_route<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut dyn IHttpContext,
) -> Pin<Box<dyn Future<Output = Result<Option<(Arc<dyn IEndpoint>, HashMap<String, String>, String)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn match_route<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut dyn IHttpContext,
) -> Pin<Box<dyn Future<Output = Result<Option<(Arc<dyn IEndpoint>, HashMap<String, String>, String)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Match an incoming request to a registered endpoint.
Returns a tuple of:
Arc<dyn IEndpoint>— the matched endpoint handler.HashMap<String, String>— route parameter values.String— the original route pattern (e.g.,"/api/users/{id}").
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".