Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions worker/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ impl<'a, D: 'a> Router<'a, D> {

/// Register an HTTP handler that will exclusively respond to HEAD requests. Enables the use of
/// `async/await` syntax in the callback.
pub fn head_async<T>(mut self, pattern: &str, func: fn(Request, RouteContext<D>) -> T) -> Self
pub fn head_async<T>(
mut self,
pattern: &str,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
{
Expand All @@ -204,7 +208,11 @@ impl<'a, D: 'a> Router<'a, D> {

/// Register an HTTP handler that will exclusively respond to GET requests. Enables the use of
/// `async/await` syntax in the callback.
pub fn get_async<T>(mut self, pattern: &str, func: fn(Request, RouteContext<D>) -> T) -> Self
pub fn get_async<T>(
mut self,
pattern: &str,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
{
Expand All @@ -218,7 +226,11 @@ impl<'a, D: 'a> Router<'a, D> {

/// Register an HTTP handler that will exclusively respond to POST requests. Enables the use of
/// `async/await` syntax in the callback.
pub fn post_async<T>(mut self, pattern: &str, func: fn(Request, RouteContext<D>) -> T) -> Self
pub fn post_async<T>(
mut self,
pattern: &str,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
{
Expand All @@ -232,7 +244,11 @@ impl<'a, D: 'a> Router<'a, D> {

/// Register an HTTP handler that will exclusively respond to PUT requests. Enables the use of
/// `async/await` syntax in the callback.
pub fn put_async<T>(mut self, pattern: &str, func: fn(Request, RouteContext<D>) -> T) -> Self
pub fn put_async<T>(
mut self,
pattern: &str,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
{
Expand All @@ -246,7 +262,11 @@ impl<'a, D: 'a> Router<'a, D> {

/// Register an HTTP handler that will exclusively respond to PATCH requests. Enables the use of
/// `async/await` syntax in the callback.
pub fn patch_async<T>(mut self, pattern: &str, func: fn(Request, RouteContext<D>) -> T) -> Self
pub fn patch_async<T>(
mut self,
pattern: &str,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
{
Expand All @@ -260,7 +280,11 @@ impl<'a, D: 'a> Router<'a, D> {

/// Register an HTTP handler that will exclusively respond to DELETE requests. Enables the use
/// of `async/await` syntax in the callback.
pub fn delete_async<T>(mut self, pattern: &str, func: fn(Request, RouteContext<D>) -> T) -> Self
pub fn delete_async<T>(
mut self,
pattern: &str,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
{
Expand All @@ -277,7 +301,7 @@ impl<'a, D: 'a> Router<'a, D> {
pub fn options_async<T>(
mut self,
pattern: &str,
func: fn(Request, RouteContext<D>) -> T,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
Expand All @@ -292,7 +316,11 @@ impl<'a, D: 'a> Router<'a, D> {

/// Register an HTTP handler that will respond to any requests. Enables the use of `async/await`
/// syntax in the callback.
pub fn on_async<T>(mut self, pattern: &str, func: fn(Request, RouteContext<D>) -> T) -> Self
pub fn on_async<T>(
mut self,
pattern: &str,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
{
Expand All @@ -309,7 +337,7 @@ impl<'a, D: 'a> Router<'a, D> {
pub fn or_else_any_method_async<T>(
mut self,
pattern: &str,
func: fn(Request, RouteContext<D>) -> T,
func: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
where
T: Future<Output = Result<Response>> + 'a,
Expand Down
Loading