aboutsummaryrefslogtreecommitdiff
path: root/src/handler
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-06 08:01:52 +0000
committerFuwn <[email protected]>2023-04-06 08:01:52 +0000
commitfff207d3cb41c5a76db234196f16d28952dfd91c (patch)
treed19f70410c049b25ce579fdaa1cf1ac984d847f7 /src/handler
parentfeat(context): bring back peer address (diff)
downloadwindmark-fff207d3cb41c5a76db234196f16d28952dfd91c.tar.xz
windmark-fff207d3cb41c5a76db234196f16d28952dfd91c.zip
feat(response): async error handler
Diffstat (limited to 'src/handler')
-rw-r--r--src/handler/response/error.rs19
-rw-r--r--src/handler/response/route.rs4
2 files changed, 17 insertions, 6 deletions
diff --git a/src/handler/response/error.rs b/src/handler/response/error.rs
index c433a46..a1a7885 100644
--- a/src/handler/response/error.rs
+++ b/src/handler/response/error.rs
@@ -16,10 +16,23 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
+use async_trait::async_trait;
+
use crate::{context::ErrorContext, Response};
#[allow(clippy::module_name_repetitions)]
-pub trait ErrorResponse: FnMut(ErrorContext) -> Response + Send + Sync {}
+#[async_trait]
+pub trait ErrorResponse: Send + Sync {
+ async fn call(&mut self, context: ErrorContext) -> Response;
+}
-impl<T> ErrorResponse for T where T: FnMut(ErrorContext) -> Response + Send + Sync
-{}
+#[async_trait]
+impl<T, F> ErrorResponse for T
+where
+ T: FnMut(ErrorContext) -> F + Send + Sync,
+ F: std::future::Future<Output = Response> + Send + 'static,
+{
+ async fn call(&mut self, context: ErrorContext) -> Response {
+ (*self)(context).await
+ }
+}
diff --git a/src/handler/response/route.rs b/src/handler/response/route.rs
index 0196363..a65b889 100644
--- a/src/handler/response/route.rs
+++ b/src/handler/response/route.rs
@@ -16,8 +16,6 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::future::Future;
-
use async_trait::async_trait;
use crate::{context::RouteContext, Response};
@@ -32,7 +30,7 @@ pub trait RouteResponse: Send + Sync {
impl<T, F> RouteResponse for T
where
T: FnMut(RouteContext<'_>) -> F + Send + Sync,
- F: Future<Output = Response> + Send + 'static,
+ F: std::future::Future<Output = Response> + Send + 'static,
{
async fn call(&mut self, context: RouteContext<'_>) -> Response {
(*self)(context).await