pub struct Router<State> { /* private fields */ }
Expand description
Encapsulate chains of Middleware
and Handler
.
Inside Server
there is always a default router which is configured
via Server::at
, however routers can also be instantiated and configured
separately. This can be a good strategy for complex servers with many
subsystems.
§Example
use hreq::prelude::*;
async fn start_server() {
let mut server = Server::new();
let mut router = Router::new();
router.at("/hello/:name").get(hello_there);
// Resulting route is /much/hello/<name>
server.at("/much").router(router);
server.listen(3000).await.unwrap();
}
async fn hello_there(req: http::Request<Body>) -> String {
format!("Hello {}", req.path_param("name").unwrap())
}
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<State> Freeze for Router<State>
impl<State> !RefUnwindSafe for Router<State>
impl<State> Send for Router<State>
impl<State> Sync for Router<State>
impl<State> Unpin for Router<State>
impl<State> !UnwindSafe for Router<State>
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