Struct peta::server::Router

source ·
pub struct Router { /* private fields */ }
Expand description

Simple mapper which maps different route to the corresponding functions which will be executed in case of match

Example

let mut router = Router::new();

router.get("/", hello_world);
router.get("/home", home);

// It is important to add default route
router.add_default(not_found);

let router = router.build();

Implementations§

build wraps router in Arc so that we can copy ref pointer in to the tokio stream and fold functions

Is used to find appropriate Node instance in Route map and return Boxed future example find(req) will return future which can be chained and executed

Create and adds Node instances to the Router, can be used to attach different requests to the router for example router.add(method::PATCH, path, func)

Router helpers methods to simplify route creation

Helper for add method which simplifies creation of get router instead of router.add(method::GET, path, func) you can write router.get(path, func)

Helper for add method which simplifies creation of post router instead of router.add(method::POST, path, func) you can write router.post(path, func)

Helper for add method which simplifies creation of put router instead of router.add(method::PUT, path, func) you can write router.put(path, func)

Helper for add method which simplifies creation of head router instead of router.add(method::HEAD, path, func) you can write router.head(path, func)

Helper for add method which simplifies creation of patch router instead of router.add(method::PATCH, path, func) you can write router.patch(path, func)

Helper for add method which simplifies creation of delete router instead of router.add(method::DELETE, path, func) you can write router.delete(path, func)

Helper for add method which simplifies creation of options router instead of router.add(method::OPTIONS, path, func) you can write router.options(path, func)

Adds default method to the Route instance, default method is executed when no matching route found can be used to response with 404 error It is mandatory to set default method

Trait Implementations§

Formats the value using the given formatter. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.