Struct treemux::Treemux [−][src]
Implementations
impl Treemux
[src]
pub fn builder() -> Builder
[src]
pub fn lookup<'b, P: AsRef<str>>(
&'b self,
method: &'b Method,
path: P
) -> Result<(Arc<Handler>, Params), bool>
[src]
&'b self,
method: &'b Method,
path: P
) -> Result<(Arc<Handler>, Params), bool>
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>
[src]
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?;
pub fn into_service(self) -> MakeRouterService<()>
[src]
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?;
pub async fn serve(&self, req: Request<Body>) -> Result<Response<Body>, Error>
[src]
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
impl Debug for Treemux
[src]
impl Default for Treemux
[src]
impl Display for Treemux
[src]
impl From<Builder> for Treemux
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Treemux
[src]
impl Send for Treemux
[src]
impl Sync for Treemux
[src]
impl Unpin for Treemux
[src]
impl !UnwindSafe for Treemux
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,