From 6909271fa6488c2ba285aa67f2faa502bd5b6be6 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 5 Apr 2023 02:47:07 +0000 Subject: feat(route): merge async and sync mount functions !! --- src/handler/response/route.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/handler/response') 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 // 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 + Send>>; + async fn call(&mut self, context: RouteContext<'_>) -> Response; } +#[async_trait] impl RouteResponse for T where T: FnMut(RouteContext<'_>) -> F + Send + Sync, F: Future + Send + 'static, { - fn call( - &mut self, - context: RouteContext<'_>, - ) -> Pin + Send>> { - Box::pin((*self)(context)) + async fn call(&mut self, context: RouteContext<'_>) -> Response { + (*self)(context).await } } -- cgit v1.2.3