Struct RouterBuilder

Source
pub struct RouterBuilder { /* private fields */ }
Expand description

A RouterBuilder enables you to build up a set of routes and their handlers to be handled by a Router.

Implementations§

Source§

impl RouterBuilder

Source

pub fn new() -> RouterBuilder

Create a new RouterBuilder with no route handlers.

Source

pub fn route<H>( &mut self, verb: Method, route: &str, handler: H, ) -> &mut RouterBuilder
where H: Fn(Request<Body>, Captures<'_>) -> Response<Body> + Send + Sync + 'static,

Install a handler for requests of method verb and which have paths matching route. There are also convenience methods named after the appropriate verb.

Source

pub fn finalize(self) -> Result<Router, Error>

Compile the routes in a RouterBuilder to produce a Router capable of handling Hyper requests.

Source

pub fn get<H>(&mut self, route: &str, handler: H) -> &mut RouterBuilder
where H: Fn(Request<Body>, Captures<'_>) -> Response<Body> + Send + Sync + 'static,

Convenience method to install a GET handler.

Source

pub fn post<H>(&mut self, route: &str, handler: H) -> &mut RouterBuilder
where H: Fn(Request<Body>, Captures<'_>) -> Response<Body> + Send + Sync + 'static,

Convenience method to install a POST handler.

Source

pub fn put<H>(&mut self, route: &str, handler: H) -> &mut RouterBuilder
where H: Fn(Request<Body>, Captures<'_>) -> Response<Body> + Send + Sync + 'static,

Convenience method to install a PUT handler.

Source

pub fn patch<H>(&mut self, route: &str, handler: H) -> &mut RouterBuilder
where H: Fn(Request<Body>, Captures<'_>) -> Response<Body> + Send + Sync + 'static,

Convenience method to install a PATCH handler.

Source

pub fn delete<H>(&mut self, route: &str, handler: H) -> &mut RouterBuilder
where H: Fn(Request<Body>, Captures<'_>) -> Response<Body> + Send + Sync + 'static,

Convenience method to install a DELETE handler.

Source

pub fn options<H>(&mut self, route: &str, handler: H) -> &mut RouterBuilder
where H: Fn(Request<Body>, Captures<'_>) -> Response<Body> + Send + Sync + 'static,

Convenience method to install an OPTIONS handler.

Source

pub fn not_found<H>(&mut self, not_found: H) -> &mut RouterBuilder
where H: Fn(Request<Body>, Captures<'_>) -> Response<Body> + Send + Sync + 'static,

Install a fallback handler for when there is no matching route for a request. If none is installed, the resulting Router will use a default handler.

Trait Implementations§

Source§

impl Default for RouterBuilder

Source§

fn default() -> RouterBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.