diff --git a/worker/src/router.rs b/worker/src/router.rs index 8c7699bde..10e572ae8 100644 --- a/worker/src/router.rs +++ b/worker/src/router.rs @@ -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(mut self, pattern: &str, func: fn(Request, RouteContext) -> T) -> Self + pub fn head_async( + mut self, + pattern: &str, + func: impl Fn(Request, RouteContext) -> T + 'a, + ) -> Self where T: Future> + 'a, { @@ -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(mut self, pattern: &str, func: fn(Request, RouteContext) -> T) -> Self + pub fn get_async( + mut self, + pattern: &str, + func: impl Fn(Request, RouteContext) -> T + 'a, + ) -> Self where T: Future> + 'a, { @@ -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(mut self, pattern: &str, func: fn(Request, RouteContext) -> T) -> Self + pub fn post_async( + mut self, + pattern: &str, + func: impl Fn(Request, RouteContext) -> T + 'a, + ) -> Self where T: Future> + 'a, { @@ -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(mut self, pattern: &str, func: fn(Request, RouteContext) -> T) -> Self + pub fn put_async( + mut self, + pattern: &str, + func: impl Fn(Request, RouteContext) -> T + 'a, + ) -> Self where T: Future> + 'a, { @@ -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(mut self, pattern: &str, func: fn(Request, RouteContext) -> T) -> Self + pub fn patch_async( + mut self, + pattern: &str, + func: impl Fn(Request, RouteContext) -> T + 'a, + ) -> Self where T: Future> + 'a, { @@ -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(mut self, pattern: &str, func: fn(Request, RouteContext) -> T) -> Self + pub fn delete_async( + mut self, + pattern: &str, + func: impl Fn(Request, RouteContext) -> T + 'a, + ) -> Self where T: Future> + 'a, { @@ -277,7 +301,7 @@ impl<'a, D: 'a> Router<'a, D> { pub fn options_async( mut self, pattern: &str, - func: fn(Request, RouteContext) -> T, + func: impl Fn(Request, RouteContext) -> T + 'a, ) -> Self where T: Future> + 'a, @@ -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(mut self, pattern: &str, func: fn(Request, RouteContext) -> T) -> Self + pub fn on_async( + mut self, + pattern: &str, + func: impl Fn(Request, RouteContext) -> T + 'a, + ) -> Self where T: Future> + 'a, { @@ -309,7 +337,7 @@ impl<'a, D: 'a> Router<'a, D> { pub fn or_else_any_method_async( mut self, pattern: &str, - func: fn(Request, RouteContext) -> T, + func: impl Fn(Request, RouteContext) -> T + 'a, ) -> Self where T: Future> + 'a,