aboutsummaryrefslogtreecommitdiff
path: root/src/handler
diff options
context:
space:
mode:
Diffstat (limited to 'src/handler')
-rw-r--r--src/handler/response/route.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/handler/response/route.rs b/src/handler/response/route.rs
index 91265a3..0196363 100644
--- a/src/handler/response/route.rs
+++ b/src/handler/response/route.rs
@@ -16,27 +16,25 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{future::Future, pin::Pin};
+use std::future::Future;
+
+use async_trait::async_trait;
use crate::{context::RouteContext, Response};
#[allow(clippy::module_name_repetitions)]
+#[async_trait]
pub trait RouteResponse: Send + Sync {
- fn call(
- &mut self,
- context: RouteContext<'_>,
- ) -> Pin<Box<dyn Future<Output = Response> + Send>>;
+ async fn call(&mut self, context: RouteContext<'_>) -> Response;
}
+#[async_trait]
impl<T, F> RouteResponse for T
where
T: FnMut(RouteContext<'_>) -> F + Send + Sync,
F: Future<Output = Response> + Send + 'static,
{
- fn call(
- &mut self,
- context: RouteContext<'_>,
- ) -> Pin<Box<dyn Future<Output = Response> + Send>> {
- Box::pin((*self)(context))
+ async fn call(&mut self, context: RouteContext<'_>) -> Response {
+ (*self)(context).await
}
}