Struct treemux::Treemux [−][src]
pub struct Treemux { /* fields omitted */ }
Implementations
Lookup allows the manual lookup of handler for a specific method and path.
If the handler is not found, it returns a Err(bool)
indicating whether a redirection should be performed to the same path with a trailing slash
use treemux::{Treemux, RouterBuilder};
use hyper::{Response, Body, Method};
let mut router = Treemux::builder();
router.get("/home", |_| {
async { Ok(Response::new(Body::from("Welcome!"))) }
});
let router: Treemux = router.into();
let res = router.lookup(&Method::GET, "/home").unwrap();
assert!(res.1.is_empty());
pub fn into_service_with_context<T: Send + Sync + 'static>(
self,
context: T
) -> MakeRouterService<T>
pub fn into_service_with_context<T: Send + Sync + 'static>(
self,
context: T
) -> MakeRouterService<T>
Converts the Treemux
into a Service
which you can serve directly with Hyper
.
If you have an existing Service
that you want to incorporate a Treemux
into, see
Treemux::serve
.
// Our router...
let router = Treemux::builder();
// Convert it into a service...
let service = router.into_service();
// Serve with hyper
hyper::Server::bind(&([127, 0, 0, 1], 3030).into())
.serve(service)
.await?;
Converts the Treemux
into a Service
which you can serve directly with Hyper
.
If you have an existing Service
that you want to incorporate a Treemux
into, see
Treemux::serve
.
// Our router...
let router = Treemux::builder();
// Convert it into a service...
let service = router.into_service();
// Serve with hyper
hyper::Server::bind(&([127, 0, 0, 1], 3030).into())
.serve(service)
.await?;
An asynchronous function from a Request
to a Response
. You will generally not need to use
this function directly, and instead use
Treemux::into_service
. However, it may be useful when
incorporating the router into a larger service.
let mut router = Treemux::builder();
let router: Arc<Treemux> = Arc::new(router.into());
let make_svc = make_service_fn(move |_| {
let router = router.clone();
async move {
Ok::<_, Infallible>(service_fn(move |req: Request<Body>| {
let router = router.clone();
async move { router.serve(req).await }
}))
}
});
let server = Server::bind(&([127, 0, 0, 1], 3000).into())
.serve(make_svc)
.await;
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Treemux
impl !UnwindSafe for Treemux
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more