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());

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

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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