Struct Router

Source
pub struct Router<'a, D> { /* private fields */ }
Expand description

A path-based HTTP router supporting exact-match or wildcard placeholders and shared data.

Implementations§

Source§

impl Router<'_, ()>

Source

pub fn new() -> Self

Construct a new Router. Or, call Router::with_data(D) to add arbitrary data that will be available to your various routes.

Source§

impl<'a, D: 'a> Router<'a, D>

Source

pub fn with_data(data: D) -> Self

Construct a new Router with arbitrary data that will be available to your various routes.

Source

pub fn head( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will exclusively respond to HEAD requests.

Source

pub fn get( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will exclusively respond to GET requests.

Source

pub fn post( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will exclusively respond to POST requests.

Source

pub fn put( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will exclusively respond to PUT requests.

Source

pub fn patch( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will exclusively respond to PATCH requests.

Source

pub fn delete( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will exclusively respond to DELETE requests.

Source

pub fn options( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will exclusively respond to OPTIONS requests.

Source

pub fn report( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will exclusively respond to REPORT requests.

Source

pub fn on( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will respond to any requests.

Source

pub fn or_else_any_method( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self

Register an HTTP handler that will respond to all methods that are not handled explicitly by other handlers.

Source

pub fn head_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will exclusively respond to HEAD requests. Enables the use of async/await syntax in the callback.

Source

pub fn get_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will exclusively respond to GET requests. Enables the use of async/await syntax in the callback.

Source

pub fn post_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will exclusively respond to POST requests. Enables the use of async/await syntax in the callback.

Source

pub fn put_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will exclusively respond to PUT requests. Enables the use of async/await syntax in the callback.

Source

pub fn patch_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will exclusively respond to PATCH requests. Enables the use of async/await syntax in the callback.

Source

pub fn delete_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will exclusively respond to DELETE requests. Enables the use of async/await syntax in the callback.

Source

pub fn options_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will exclusively respond to OPTIONS requests. Enables the use of async/await syntax in the callback.

Source

pub fn on_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will respond to any requests. Enables the use of async/await syntax in the callback.

Source

pub fn or_else_any_method_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
where T: Future<Output = Result<Response>> + 'a,

Register an HTTP handler that will respond to all methods that are not handled explicitly by other handlers. Enables the use of async/await syntax in the callback.

Source

pub async fn run(self, req: Request, env: Env) -> Result<Response>

Handle the request provided to the Router and return a Future.

Trait Implementations§

Source§

impl Debug for Router<'_, ()>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, D> !Freeze for Router<'a, D>

§

impl<'a, D> !RefUnwindSafe for Router<'a, D>

§

impl<'a, D> !Send for Router<'a, D>

§

impl<'a, D> !Sync for Router<'a, D>

§

impl<'a, D> Unpin for Router<'a, D>
where D: Unpin,

§

impl<'a, D> !UnwindSafe for Router<'a, D>

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,