aboutsummaryrefslogtreecommitdiff
path: root/src/handler
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-05 02:47:07 +0000
committerFuwn <[email protected]>2023-04-05 02:47:07 +0000
commit6909271fa6488c2ba285aa67f2faa502bd5b6be6 (patch)
treeb76e33cdc88fd9bde2e59af0658c0302745c2be4 /src/handler
parentfeat(module): async module support (diff)
downloadwindmark-6909271fa6488c2ba285aa67f2faa502bd5b6be6.tar.xz
windmark-6909271fa6488c2ba285aa67f2faa502bd5b6be6.zip
feat(route): merge async and sync mount functions !!
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
}
}