Skip to main content

Router

Struct Router 

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

A request router: match by method and path, dispatch to a handler.

See the module docs for the pattern syntax and an example. Build one with Router::new, add routes with the per-method builders (or the generic route), and optionally set a fallback for unmatched paths. The result implements Handler.

Implementations§

Source§

impl Router

Source

pub fn new() -> Router

An empty router. Without any routes (or a fallback) it answers 404.

Source

pub fn route<H>(self, method: Method, pattern: &str, handler: H) -> Router
where H: RouteHandler + 'static,

Register handler for method requests matching pattern.

Source

pub fn get<H: RouteHandler + 'static>(self, pattern: &str, handler: H) -> Router

Register a GET route.

Source

pub fn post<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router

Register a POST route.

Source

pub fn put<H: RouteHandler + 'static>(self, pattern: &str, handler: H) -> Router

Register a PUT route.

Source

pub fn delete<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router

Register a DELETE route.

Source

pub fn patch<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router

Register a PATCH route.

Source

pub fn head<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router

Register a HEAD route.

Source

pub fn options<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router

Register an OPTIONS route.

Source

pub fn fallback<H: RouteHandler + 'static>(self, handler: H) -> Router

Set the handler invoked when no route matches the path (otherwise 404).

Trait Implementations§

Source§

impl Default for Router

Source§

fn default() -> Router

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

impl Handler for Router

Source§

fn handle(&self, req: &Request) -> Response

Handle one request and produce the response to send back.

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.