Struct treemux::Treemux[][src]

pub struct Treemux { /* fields omitted */ }

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]

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]

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.