pub struct Router {
pub routes: Vec<Route>,
}Expand description
Router for managing routes and dispatching requests.
The router uses optimized handler dispatch that enables:
- Monomorphization of handler code
- Inlining of handler bodies
- Minimal allocation in the hot path
Fields§
§routes: Vec<Route>Implementations§
Source§impl Router
impl Router
Sourcepub fn get<H, Args>(&mut self, path: impl Into<String>, handler: H) -> &mut Selfwhere
H: IntoHandler<Args>,
pub fn get<H, Args>(&mut self, path: impl Into<String>, handler: H) -> &mut Selfwhere
H: IntoHandler<Args>,
Add a GET route with an optimized handler.
Sourcepub fn post<H, Args>(
&mut self,
path: impl Into<String>,
handler: H,
) -> &mut Selfwhere
H: IntoHandler<Args>,
pub fn post<H, Args>(
&mut self,
path: impl Into<String>,
handler: H,
) -> &mut Selfwhere
H: IntoHandler<Args>,
Add a POST route with an optimized handler.
Sourcepub fn put<H, Args>(&mut self, path: impl Into<String>, handler: H) -> &mut Selfwhere
H: IntoHandler<Args>,
pub fn put<H, Args>(&mut self, path: impl Into<String>, handler: H) -> &mut Selfwhere
H: IntoHandler<Args>,
Add a PUT route with an optimized handler.
Sourcepub fn delete<H, Args>(
&mut self,
path: impl Into<String>,
handler: H,
) -> &mut Selfwhere
H: IntoHandler<Args>,
pub fn delete<H, Args>(
&mut self,
path: impl Into<String>,
handler: H,
) -> &mut Selfwhere
H: IntoHandler<Args>,
Add a DELETE route with an optimized handler.
Sourcepub fn patch<H, Args>(
&mut self,
path: impl Into<String>,
handler: H,
) -> &mut Selfwhere
H: IntoHandler<Args>,
pub fn patch<H, Args>(
&mut self,
path: impl Into<String>,
handler: H,
) -> &mut Selfwhere
H: IntoHandler<Args>,
Add a PATCH route with an optimized handler.
Sourcepub fn match_route(
&self,
method: &str,
path: &str,
) -> Option<(BoxedHandler, HashMap<String, String>)>
pub fn match_route( &self, method: &str, path: &str, ) -> Option<(BoxedHandler, HashMap<String, String>)>
Match a route without executing the handler. Returns the handler and path parameters if a route matches. Useful for route lookup benchmarking and inspection.
Sourcepub async fn route(&self, request: HttpRequest) -> Result<HttpResponse, Error>
pub async fn route(&self, request: HttpRequest) -> Result<HttpResponse, Error>
Find a route that matches the request and execute the handler.
This is the main hot path for request handling. The handler dispatch is optimized via monomorphization - the actual handler code can be inlined by the compiler.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Router
impl !RefUnwindSafe for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl !UnwindSafe for Router
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging