Struct worker::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<'a> Router<'a, ()>

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 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere 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.

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.